clang-tools  3.9.0
HeaderGuard.h
Go to the documentation of this file.
1 //===--- HeaderGuard.h - clang-tidy -----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace utils {
18 
19 /// Finds and fixes header guards.
21 public:
22  HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
23  : ClangTidyCheck(Name, Context) {}
24  void registerPPCallbacks(CompilerInstance &Compiler) override;
25 
26  /// Returns ``true`` if the check should suggest inserting a trailing comment
27  /// on the ``#endif`` of the header guard. It will use the same name as
28  /// returned by ``HeaderGuardCheck::getHeaderGuard``.
29  virtual bool shouldSuggestEndifComment(StringRef Filename);
30  /// Returns ``true`` if the check should suggest changing an existing header
31  /// guard to the string returned by ``HeaderGuardCheck::getHeaderGuard``.
32  virtual bool shouldFixHeaderGuard(StringRef Filename);
33  /// Returns ``true`` if the check should add a header guard to the file
34  /// if it has none.
35  virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename);
36  /// Returns a replacement for the ``#endif`` line with a comment mentioning
37  /// \p HeaderGuard. The replacement should start with ``endif``.
38  virtual std::string formatEndIf(StringRef HeaderGuard);
39  /// Gets the canonical header guard for a file.
40  virtual std::string getHeaderGuard(StringRef Filename,
41  StringRef OldGuard = StringRef()) = 0;
42 };
43 
44 } // namespace utils
45 } // namespace tidy
46 } // namespace clang
47 
48 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
virtual bool shouldSuggestEndifComment(StringRef Filename)
Returns true if the check should suggest inserting a trailing comment on the #endif of the header gua...
const std::string Name
Definition: USRFinder.cpp:140
virtual std::string getHeaderGuard(StringRef Filename, StringRef OldGuard=StringRef())=0
Gets the canonical header guard for a file.
Finds and fixes header guards.
Definition: HeaderGuard.h:20
HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
Definition: HeaderGuard.h:22
Base class for all clang-tidy checks.
Definition: ClangTidy.h:110
virtual std::string formatEndIf(StringRef HeaderGuard)
Returns a replacement for the #endif line with a comment mentioning HeaderGuard.
std::string Filename
Filename as a string.
virtual bool shouldFixHeaderGuard(StringRef Filename)
Returns true if the check should suggest changing an existing header guard to the string returned by ...
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename)
Returns true if the check should add a header guard to the file if it has none.