clang-tools 23.0.0git
HeaderGuard.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
11
12#include "../ClangTidyCheck.h"
13
14namespace clang::tidy::utils {
15
16/// Finds and fixes header guards.
18public:
19 HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
20 : ClangTidyCheck(Name, Context) {}
21
22 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
23 Preprocessor *ModuleExpanderPP) override;
24
25 /// Ensure that the provided header guard is a non-reserved identifier.
26 std::string sanitizeHeaderGuard(StringRef Guard);
27
28 /// Returns ``true`` if the check should suggest inserting a trailing comment
29 /// on the ``#endif`` of the header guard. It will use the same name as
30 /// returned by ``HeaderGuardCheck::getHeaderGuard``.
31 virtual bool shouldSuggestEndifComment(StringRef Filename);
32 /// Returns ``true`` if the check should suggest changing an existing header
33 /// guard to the string returned by ``HeaderGuardCheck::getHeaderGuard``.
34 virtual bool shouldFixHeaderGuard(StringRef Filename);
35 /// Returns ``true`` if the check should add a header guard to the file
36 /// if it has none.
37 virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename);
38 /// Returns a replacement for the ``#endif`` line with a comment mentioning
39 /// \p HeaderGuard. The replacement should start with ``endif``.
40 virtual std::string formatEndIf(StringRef HeaderGuard);
41 /// Gets the canonical header guard for a file.
42 virtual std::string getHeaderGuard(StringRef Filename,
43 StringRef OldGuard = StringRef()) = 0;
44};
45
46} // namespace clang::tidy::utils
47
48#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
std::string sanitizeHeaderGuard(StringRef Guard)
Ensure that the provided header guard is a non-reserved identifier.
virtual std::string getHeaderGuard(StringRef Filename, StringRef OldGuard=StringRef())=0
Gets the canonical header guard for a file.
HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
Definition HeaderGuard.h:19
virtual std::string formatEndIf(StringRef HeaderGuard)
Returns true if the check should suggest inserting a trailing comment / on the #endif of the header g...
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override