mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-19 11:35:51 -04:00

Summary: Change the namespace for llvm checkers from 'llvm' to 'llvm_check', and modify add_new_check.py and rename_check.py to support the new namespace. Checker, file, and directory names remain unchanged. Used new version of rename_check.py to make the change in existing llvm checkers, but had to fix LLVMTidyModule.cpp and LLVMModuleTest.cpp by hand. The changes made by rename_check.py are idempotent, so if accidentally run multiple times, it won't do anything. Reviewed By: aaron.ballman Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D60629 llvm-svn: 360450
55 lines
1.9 KiB
C++
55 lines
1.9 KiB
C++
//===--- HeaderGuardCheck.cpp - clang-tidy --------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "HeaderGuardCheck.h"
|
|
|
|
namespace clang {
|
|
namespace tidy {
|
|
namespace llvm_check {
|
|
|
|
LLVMHeaderGuardCheck::LLVMHeaderGuardCheck(StringRef Name,
|
|
ClangTidyContext *Context)
|
|
: HeaderGuardCheck(Name, Context) {}
|
|
|
|
std::string LLVMHeaderGuardCheck::getHeaderGuard(StringRef Filename,
|
|
StringRef OldGuard) {
|
|
std::string Guard = tooling::getAbsolutePath(Filename);
|
|
|
|
// Sanitize the path. There are some rules for compatibility with the historic
|
|
// style in include/llvm and include/clang which we want to preserve.
|
|
|
|
// We don't want _INCLUDE_ in our guards.
|
|
size_t PosInclude = Guard.rfind("include/");
|
|
if (PosInclude != StringRef::npos)
|
|
Guard = Guard.substr(PosInclude + std::strlen("include/"));
|
|
|
|
// For clang we drop the _TOOLS_.
|
|
size_t PosToolsClang = Guard.rfind("tools/clang/");
|
|
if (PosToolsClang != StringRef::npos)
|
|
Guard = Guard.substr(PosToolsClang + std::strlen("tools/"));
|
|
|
|
// The remainder is LLVM_FULL_PATH_TO_HEADER_H
|
|
size_t PosLLVM = Guard.rfind("llvm/");
|
|
if (PosLLVM != StringRef::npos)
|
|
Guard = Guard.substr(PosLLVM);
|
|
|
|
std::replace(Guard.begin(), Guard.end(), '/', '_');
|
|
std::replace(Guard.begin(), Guard.end(), '.', '_');
|
|
std::replace(Guard.begin(), Guard.end(), '-', '_');
|
|
|
|
// The prevalent style in clang is LLVM_CLANG_FOO_BAR_H
|
|
if (StringRef(Guard).startswith("clang"))
|
|
Guard = "LLVM_" + Guard;
|
|
|
|
return StringRef(Guard).upper();
|
|
}
|
|
|
|
} // namespace llvm_check
|
|
} // namespace tidy
|
|
} // namespace clang
|