2015-08-11 19:37:48 +08:00
|
|
|
//===---------- IncludeInserter.h - clang-tidy ----------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-08-11 19:37:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
|
|
|
|
|
|
|
|
#include "IncludeSorter.h"
|
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Lex/PPCallbacks.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2016-05-03 10:54:05 +08:00
|
|
|
namespace utils {
|
2015-08-11 19:37:48 +08:00
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Produces fixes to insert specified includes to source files, if not
|
2016-06-17 19:43:33 +08:00
|
|
|
/// yet present.
|
|
|
|
///
|
2018-11-02 23:29:37 +08:00
|
|
|
/// ``IncludeInserter`` can be used in clang-tidy checks in the following way:
|
2016-06-17 19:43:33 +08:00
|
|
|
/// \code
|
2018-11-02 23:29:37 +08:00
|
|
|
/// #include "../utils/IncludeInserter.h"
|
|
|
|
/// #include "clang/Frontend/CompilerInstance.h"
|
|
|
|
///
|
2016-06-17 19:43:33 +08:00
|
|
|
/// class MyCheck : public ClangTidyCheck {
|
|
|
|
/// public:
|
2019-03-23 02:58:12 +08:00
|
|
|
/// void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
|
|
|
|
/// Preprocessor *ModuleExpanderPP) override {
|
2019-08-15 07:52:23 +08:00
|
|
|
/// Inserter = std::make_unique<IncludeInserter>(
|
2019-03-23 02:58:12 +08:00
|
|
|
/// SM, getLangOpts(), utils::IncludeSorter::IS_Google);
|
|
|
|
/// PP->addPPCallbacks(Inserter->CreatePPCallbacks());
|
2016-06-17 19:43:33 +08:00
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
|
|
|
|
///
|
|
|
|
/// void check(
|
|
|
|
/// const ast_matchers::MatchFinder::MatchResult& Result) override {
|
|
|
|
/// ...
|
|
|
|
/// Inserter->CreateIncludeInsertion(
|
|
|
|
/// Result.SourceManager->getMainFileID(), "path/to/Header.h",
|
|
|
|
/// /*IsAngled=*/false);
|
|
|
|
/// ...
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// private:
|
2018-11-02 23:29:37 +08:00
|
|
|
/// std::unique_ptr<clang::tidy::utils::IncludeInserter> Inserter;
|
2016-06-17 19:43:33 +08:00
|
|
|
/// };
|
|
|
|
/// \endcode
|
2015-08-11 19:37:48 +08:00
|
|
|
class IncludeInserter {
|
|
|
|
public:
|
|
|
|
IncludeInserter(const SourceManager &SourceMgr, const LangOptions &LangOpts,
|
|
|
|
IncludeSorter::IncludeStyle Style);
|
|
|
|
~IncludeInserter();
|
|
|
|
|
2016-06-17 19:43:33 +08:00
|
|
|
/// Create ``PPCallbacks`` for registration with the compiler's preprocessor.
|
2015-08-11 19:37:48 +08:00
|
|
|
std::unique_ptr<PPCallbacks> CreatePPCallbacks();
|
|
|
|
|
2016-06-17 19:43:33 +08:00
|
|
|
/// Creates a \p Header inclusion directive fixit. Returns ``llvm::None`` on
|
|
|
|
/// error or if inclusion directive already exists.
|
2015-08-11 19:37:48 +08:00
|
|
|
llvm::Optional<FixItHint>
|
|
|
|
CreateIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
|
|
|
|
|
|
|
|
private:
|
2016-05-16 22:34:20 +08:00
|
|
|
void AddInclude(StringRef FileName, bool IsAngled,
|
|
|
|
SourceLocation HashLocation, SourceLocation EndLocation);
|
2015-08-11 19:37:48 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile;
|
|
|
|
llvm::DenseMap<FileID, std::set<std::string>> InsertedHeaders;
|
|
|
|
const SourceManager &SourceMgr;
|
|
|
|
const LangOptions &LangOpts;
|
|
|
|
const IncludeSorter::IncludeStyle Style;
|
|
|
|
friend class IncludeInserterCallback;
|
|
|
|
};
|
|
|
|
|
2016-05-03 10:54:05 +08:00
|
|
|
} // namespace utils
|
2015-08-11 19:37:48 +08:00
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDEINSERTER_H
|