10#include "clang/Tooling/Tooling.h"
11#include "llvm/Support/Path.h"
17 : HeaderGuardCheck(
Name, Context) {}
21 std::string Guard = tooling::getAbsolutePath(
Filename);
25 Guard = llvm::sys::path::convert_to_slash(Guard);
31 size_t PosInclude = Guard.rfind(
"include/");
32 if (PosInclude != StringRef::npos)
33 Guard = Guard.substr(PosInclude + std::strlen(
"include/"));
36 size_t PosToolsClang = Guard.rfind(
"tools/clang/");
37 if (PosToolsClang != StringRef::npos)
38 Guard = Guard.substr(PosToolsClang + std::strlen(
"tools/"));
42 const static StringRef LLVMProject =
"/llvm-project/";
43 size_t PosLLVMProject = Guard.rfind(std::string(LLVMProject));
44 if (PosLLVMProject != StringRef::npos)
45 Guard = Guard.replace(PosLLVMProject, LLVMProject.size(),
"/llvm/");
48 size_t PosLLVM = Guard.rfind(
"llvm/");
49 if (PosLLVM != StringRef::npos)
50 Guard = Guard.substr(PosLLVM);
52 std::replace(Guard.begin(), Guard.end(),
'/',
'_');
53 std::replace(Guard.begin(), Guard.end(),
'.',
'_');
54 std::replace(Guard.begin(), Guard.end(),
'-',
'_');
57 if (StringRef(Guard).starts_with(
"clang"))
58 Guard =
"LLVM_" + Guard;
61 if (StringRef(Guard).starts_with(
"flang"))
62 Guard =
"FORTRAN" + Guard.substr(
sizeof(
"flang") - 1);
64 return StringRef(Guard).upper();
llvm::SmallString< 256U > Name
std::string Filename
Filename as a string.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.