Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:22

0001 //===--- HeaderGuard.h - clang-tidy -----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/FileExtensionsUtils.h"
0014 
0015 namespace clang::tidy::utils {
0016 
0017 /// Finds and fixes header guards.
0018 class HeaderGuardCheck : public ClangTidyCheck {
0019 public:
0020   HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
0021       : ClangTidyCheck(Name, Context),
0022         HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
0023 
0024   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0025                            Preprocessor *ModuleExpanderPP) override;
0026 
0027   /// Ensure that the provided header guard is a non-reserved identifier.
0028   std::string sanitizeHeaderGuard(StringRef Guard);
0029 
0030   /// Returns ``true`` if the check should suggest inserting a trailing comment
0031   /// on the ``#endif`` of the header guard. It will use the same name as
0032   /// returned by ``HeaderGuardCheck::getHeaderGuard``.
0033   virtual bool shouldSuggestEndifComment(StringRef Filename);
0034   /// Returns ``true`` if the check should suggest changing an existing header
0035   /// guard to the string returned by ``HeaderGuardCheck::getHeaderGuard``.
0036   virtual bool shouldFixHeaderGuard(StringRef Filename);
0037   /// Returns ``true`` if the check should add a header guard to the file
0038   /// if it has none.
0039   virtual bool shouldSuggestToAddHeaderGuard(StringRef Filename);
0040   /// Returns a replacement for the ``#endif`` line with a comment mentioning
0041   /// \p HeaderGuard. The replacement should start with ``endif``.
0042   virtual std::string formatEndIf(StringRef HeaderGuard);
0043   /// Gets the canonical header guard for a file.
0044   virtual std::string getHeaderGuard(StringRef Filename,
0045                                      StringRef OldGuard = StringRef()) = 0;
0046 
0047 private:
0048   FileExtensionsSet HeaderFileExtensions;
0049 };
0050 
0051 } // namespace clang::tidy::utils
0052 
0053 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_HEADERGUARD_H