[clang-tools-extra] r279814 - [clang-tidy] Some tweaks on header guard checks.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 26 04:15:39 PDT 2016
Author: hokein
Date: Fri Aug 26 06:15:38 2016
New Revision: 279814
URL: http://llvm.org/viewvc/llvm-project?rev=279814&view=rev
Log:
[clang-tidy] Some tweaks on header guard checks.
* Implement missing storeOption interfaces.
* Remove unnecessary parameter copy in isHeaderFileExtension.
* Fix doc style.
Modified:
clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h
clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h
clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-header-guard.rst
Modified: clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp?rev=279814&r1=279813&r2=279814&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp Fri Aug 26 06:15:38 2016
@@ -13,6 +13,19 @@ namespace clang {
namespace tidy {
namespace llvm {
+LLVMHeaderGuardCheck::LLVMHeaderGuardCheck(StringRef Name,
+ ClangTidyContext* Context)
+ : HeaderGuardCheck(Name, Context),
+ RawStringHeaderFileExtensions(
+ Options.getLocalOrGlobal("HeaderFileExtensions", ",h,hh,hpp,hxx")) {
+ utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
+ HeaderFileExtensions, ',');
+}
+
+void LLVMHeaderGuardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
+}
+
bool LLVMHeaderGuardCheck::shouldFixHeaderGuard(StringRef FileName) {
return utils::isHeaderFileExtension(FileName, HeaderFileExtensions);
}
Modified: clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h?rev=279814&r1=279813&r2=279814&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h Fri Aug 26 06:15:38 2016
@@ -27,13 +27,9 @@ namespace llvm {
/// empty string between "," if there are other filename extensions.
class LLVMHeaderGuardCheck : public utils::HeaderGuardCheck {
public:
- LLVMHeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
- : HeaderGuardCheck(Name, Context),
- RawStringHeaderFileExtensions(
- Options.getLocalOrGlobal("HeaderFileExtensions", ",h,hh,hpp,hxx")) {
- utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
- HeaderFileExtensions, ',');
- }
+ LLVMHeaderGuardCheck(StringRef Name, ClangTidyContext *Context);
+
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
bool shouldSuggestEndifComment(StringRef Filename) override { return false; }
bool shouldFixHeaderGuard(StringRef Filename) override;
std::string getHeaderGuard(StringRef Filename, StringRef OldGuard) override;
Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp?rev=279814&r1=279813&r2=279814&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.cpp Fri Aug 26 06:15:38 2016
@@ -19,28 +19,24 @@ bool isExpansionLocInHeaderFile(
SourceLocation Loc, const SourceManager &SM,
const HeaderFileExtensionsSet &HeaderFileExtensions) {
SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
- StringRef FileExtension =
- llvm::sys::path::extension(SM.getFilename(ExpansionLoc));
- return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
+ return isHeaderFileExtension(SM.getFilename(ExpansionLoc),
+ HeaderFileExtensions);
}
bool isPresumedLocInHeaderFile(
SourceLocation Loc, SourceManager &SM,
const HeaderFileExtensionsSet &HeaderFileExtensions) {
PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
- StringRef FileExtension =
- llvm::sys::path::extension(PresumedLocation.getFilename());
- return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
+ return isHeaderFileExtension(PresumedLocation.getFilename(),
+ HeaderFileExtensions);
}
bool isSpellingLocInHeaderFile(
SourceLocation Loc, SourceManager &SM,
const HeaderFileExtensionsSet &HeaderFileExtensions) {
SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
- StringRef FileExtension =
- llvm::sys::path::extension(SM.getFilename(SpellingLoc));
-
- return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
+ return isHeaderFileExtension(SM.getFilename(SpellingLoc),
+ HeaderFileExtensions);
}
bool parseHeaderFileExtensions(StringRef AllHeaderFileExtensions,
@@ -61,13 +57,13 @@ bool parseHeaderFileExtensions(StringRef
return true;
}
-bool isHeaderFileExtension(StringRef FileName,
- HeaderFileExtensionsSet HeaderFileExtensions) {
- StringRef extension = ::llvm::sys::path::extension(FileName);
- if (extension.startswith("."))
- extension = extension.substr(1);
-
- return HeaderFileExtensions.count(extension) > 0;
+bool isHeaderFileExtension(
+ StringRef FileName, const HeaderFileExtensionsSet &HeaderFileExtensions) {
+ StringRef extension = llvm::sys::path::extension(FileName);
+ if (extension.empty())
+ return false;
+ // Skip "." prefix.
+ return HeaderFileExtensions.count(extension.substr(1)) > 0;
}
} // namespace utils
Modified: clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h?rev=279814&r1=279813&r2=279814&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h Fri Aug 26 06:15:38 2016
@@ -43,7 +43,7 @@ bool parseHeaderFileExtensions(StringRef
/// \brief Decides whether a file has a header file extension.
bool isHeaderFileExtension(StringRef FileName,
- HeaderFileExtensionsSet HeaderFileExtensions);
+ const HeaderFileExtensionsSet &HeaderFileExtensions);
} // namespace utils
} // namespace tidy
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-header-guard.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-header-guard.rst?rev=279814&r1=279813&r2=279814&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-header-guard.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/llvm-header-guard.rst Fri Aug 26 06:15:38 2016
@@ -10,4 +10,7 @@ Options
.. option:: HeaderFileExtensions
- A comma-separated list of filename extensions of header files (The filename extension should not contain "." prefix). Default value is ",h,hh,hpp,hxx". For extension-less header files, using an empty string or leaving an empty string between "," if there are other filename extensions.
+ A comma-separated list of filename extensions of header files (The filename
+ extension should not contain "." prefix). Default value is ",h,hh,hpp,hxx".
+ For extension-less header files, using an empty string or leaving an empty
+ string between "," if there are other filename extensions.
More information about the cfe-commits
mailing list