clang-tools  3.8.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 
18 /// Finds and fixes header guards.
20 public:
21  HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
22  : ClangTidyCheck(Name, Context) {}
23  void registerPPCallbacks(CompilerInstance &Compiler) override;
24 
25  /// \brief Returns true if the checker should suggest inserting a trailing
26  /// comment on the #endif of the header guard. It will use the same name as
27  /// returned by getHeaderGuard.
28  virtual bool shouldSuggestEndifComment(StringRef Filename);
29  /// \brief Returns true if the checker should suggest changing an existing
30  /// header guard to the string returned by getHeaderGuard.
31  virtual bool shouldFixHeaderGuard(StringRef Filename);
32  /// \brief Returns true if the checker should add a header guard to the file
33  /// if it has none.
34  virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename);
35  /// \brief Returns a replacement for endif line with a comment mentioning
36  /// \p HeaderGuard. The replacement should start with "endif".
37  virtual std::string formatEndIf(StringRef HeaderGuard);
38  /// \brief Get the canonical header guard for a file.
39  virtual std::string getHeaderGuard(StringRef Filename,
40  StringRef OldGuard = StringRef()) = 0;
41 };
42 
43 } // namespace tidy
44 } // namespace clang
45 
46 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
virtual std::string formatEndIf(StringRef HeaderGuard)
Returns a replacement for endif line with a comment mentioning HeaderGuard.
StringHandle Name
virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename)
Returns true if the checker should add a header guard to the file if it has none. ...
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
virtual bool shouldSuggestEndifComment(StringRef Filename)
Returns true if the checker should suggest inserting a trailing comment on the #endif of the header g...
std::string Filename
Filename as a string.
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
virtual bool shouldFixHeaderGuard(StringRef Filename)
Returns true if the checker should suggest changing an existing header guard to the string returned b...
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
Definition: HeaderGuard.h:21
Finds and fixes header guards.
Definition: HeaderGuard.h:19
virtual std::string getHeaderGuard(StringRef Filename, StringRef OldGuard=StringRef())=0
Get the canonical header guard for a file.