[PATCH] D91908: [clang-tidy] Use compiled regex for AllowedRegexp in macro usage check
Shane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 21 12:26:23 PST 2020
smhc updated this revision to Diff 306870.
smhc added a comment.
Thanks - I had it like that originally but was not sure how often MacroUsageCallbacks would be instantiated or whether there was a many-to-one relationship. I've now modified it to create and maintain the regex object as a member of MacroUsageCallbacks.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91908/new/
https://reviews.llvm.org/D91908
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -32,8 +32,8 @@
class MacroUsageCallbacks : public PPCallbacks {
public:
MacroUsageCallbacks(MacroUsageCheck *Check, const SourceManager &SM,
- StringRef RegExp, bool CapsOnly, bool IgnoreCommandLine)
- : Check(Check), SM(SM), RegExp(RegExp), CheckCapsOnly(CapsOnly),
+ StringRef RegExpStr, bool CapsOnly, bool IgnoreCommandLine)
+ : Check(Check), SM(SM), RegExp(RegExpStr), CheckCapsOnly(CapsOnly),
IgnoreCommandLineMacros(IgnoreCommandLine) {}
void MacroDefined(const Token &MacroNameTok,
const MacroDirective *MD) override {
@@ -47,7 +47,7 @@
return;
StringRef MacroName = MacroNameTok.getIdentifierInfo()->getName();
- if (!CheckCapsOnly && !llvm::Regex(RegExp).match(MacroName))
+ if (!CheckCapsOnly && !RegExp.match(MacroName))
Check->warnMacro(MD, MacroName);
if (CheckCapsOnly && !isCapsOnly(MacroName))
@@ -57,7 +57,7 @@
private:
MacroUsageCheck *Check;
const SourceManager &SM;
- StringRef RegExp;
+ const llvm::Regex RegExp;
bool CheckCapsOnly;
bool IgnoreCommandLineMacros;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91908.306870.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201121/bed1f6ed/attachment.bin>
More information about the cfe-commits
mailing list