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"
|
2020-07-27 19:48:53 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2015-08-11 19:37:48 +08:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace clang {
|
2020-07-27 19:48:53 +08:00
|
|
|
class Preprocessor;
|
2015-08-11 19:37:48 +08:00
|
|
|
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
|
2020-07-27 19:48:53 +08:00
|
|
|
/// #include "../ClangTidyCheck.h"
|
2018-11-02 23:29:37 +08:00
|
|
|
/// #include "../utils/IncludeInserter.h"
|
2020-07-27 19:48:53 +08:00
|
|
|
///
|
|
|
|
/// namespace clang {
|
|
|
|
/// namespace tidy {
|
2018-11-02 23:29:37 +08:00
|
|
|
///
|
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 {
|
2020-07-27 19:48:53 +08:00
|
|
|
/// Inserter.registerPreprocessor();
|
2016-06-17 19:43:33 +08:00
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// void registerMatchers(ast_matchers::MatchFinder* Finder) override { ... }
|
|
|
|
///
|
|
|
|
/// void check(
|
|
|
|
/// const ast_matchers::MatchFinder::MatchResult& Result) override {
|
|
|
|
/// ...
|
2020-07-27 19:48:53 +08:00
|
|
|
/// Inserter.createMainFileIncludeInsertion("path/to/Header.h",
|
|
|
|
/// /*IsAngled=*/false);
|
2016-06-17 19:43:33 +08:00
|
|
|
/// ...
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// private:
|
2020-07-27 19:48:53 +08:00
|
|
|
/// utils::IncludeInserter Inserter{utils::IncludeSorter::IS_Google};
|
2016-06-17 19:43:33 +08:00
|
|
|
/// };
|
2020-07-27 19:48:53 +08:00
|
|
|
/// } // namespace tidy
|
|
|
|
/// } // namespace clang
|
2016-06-17 19:43:33 +08:00
|
|
|
/// \endcode
|
2015-08-11 19:37:48 +08:00
|
|
|
class IncludeInserter {
|
|
|
|
public:
|
2020-07-27 19:48:53 +08:00
|
|
|
/// Initializes the IncludeInserter using the IncludeStyle \p Style.
|
|
|
|
/// In most cases the \p Style will be retrieved from the ClangTidyOptions
|
|
|
|
/// using \code
|
|
|
|
/// Options.getLocalOrGlobal("IncludeStyle", <DefaultStyle>)
|
|
|
|
/// \endcode
|
|
|
|
explicit IncludeInserter(IncludeSorter::IncludeStyle Style);
|
|
|
|
|
|
|
|
/// Registers this with the Preprocessor \p PP, must be called before this
|
|
|
|
/// class is used.
|
|
|
|
void registerPreprocessor(Preprocessor *PP);
|
2015-08-11 19:37:48 +08:00
|
|
|
|
2020-07-27 19:48:53 +08:00
|
|
|
/// Creates a \p Header inclusion directive fixit in the File \p FileID.
|
|
|
|
/// Returns ``llvm::None`` on error or if the inclusion directive already
|
|
|
|
/// exists.
|
|
|
|
llvm::Optional<FixItHint>
|
|
|
|
createIncludeInsertion(FileID FileID, llvm::StringRef Header, bool IsAngled);
|
2015-08-11 19:37:48 +08:00
|
|
|
|
2020-07-27 19:48:53 +08:00
|
|
|
/// Creates a \p Header inclusion directive fixit in the main file.
|
|
|
|
/// Returns``llvm::None`` on error or if the inclusion directive already
|
|
|
|
/// exists.
|
2015-08-11 19:37:48 +08:00
|
|
|
llvm::Optional<FixItHint>
|
2020-07-27 19:48:53 +08:00
|
|
|
createMainFileIncludeInsertion(llvm::StringRef Header, bool IsAngled);
|
|
|
|
|
|
|
|
IncludeSorter::IncludeStyle getStyle() const { return Style; }
|
2015-08-11 19:37:48 +08:00
|
|
|
|
|
|
|
private:
|
2020-07-27 19:48:53 +08:00
|
|
|
void addInclude(StringRef FileName, bool IsAngled,
|
2016-05-16 22:34:20 +08:00
|
|
|
SourceLocation HashLocation, SourceLocation EndLocation);
|
2015-08-11 19:37:48 +08:00
|
|
|
|
2020-06-18 02:48:12 +08:00
|
|
|
IncludeSorter &getOrCreate(FileID FileID);
|
|
|
|
|
2015-08-11 19:37:48 +08:00
|
|
|
llvm::DenseMap<FileID, std::unique_ptr<IncludeSorter>> IncludeSorterByFile;
|
2020-07-27 19:48:53 +08:00
|
|
|
llvm::DenseMap<FileID, llvm::StringSet<>> InsertedHeaders;
|
|
|
|
const SourceManager *SourceMgr{nullptr};
|
2015-08-11 19:37:48 +08:00
|
|
|
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
|