clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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.
19 class HeaderGuardCheck : public ClangTidyCheck {
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
clang::tidy::HeaderGuardCheck::formatEndIf
virtual std::string formatEndIf(StringRef HeaderGuard)
Returns a replacement for endif line with a comment mentioning HeaderGuard.
Definition: HeaderGuard.cpp:298
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::HeaderGuardCheck::shouldSuggestToAddHeaderGuard
virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename)
Returns true if the checker should add a header guard to the file if it has none. ...
Definition: HeaderGuard.cpp:294
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::HeaderGuardCheck::shouldSuggestEndifComment
virtual bool shouldSuggestEndifComment(StringRef Filename)
Returns true if the checker should suggest inserting a trailing comment on the #endif of the header g...
Definition: HeaderGuard.cpp:288
Filename
std::string Filename
Filename as a string.
Definition: IncludeOrderCheck.cpp:36
clang::tidy::HeaderGuardCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: HeaderGuard.cpp:282
clang::tidy::HeaderGuardCheck::shouldFixHeaderGuard
virtual bool shouldFixHeaderGuard(StringRef Filename)
Returns true if the checker should suggest changing an existing header guard to the string returned b...
Definition: HeaderGuard.cpp:292
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
clang::tidy::HeaderGuardCheck::HeaderGuardCheck
HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
Definition: HeaderGuard.h:21
clang::tidy::HeaderGuardCheck
Finds and fixes header guards.
Definition: HeaderGuard.h:19
clang::tidy::HeaderGuardCheck::getHeaderGuard
virtual std::string getHeaderGuard(StringRef Filename, StringRef OldGuard=StringRef())=0
Get the canonical header guard for a file.