[PATCH] D59650: [NFC] ExceptionEscapeCheck: small refactoring
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 21 14:35:37 PDT 2019
lebedev.ri updated this revision to Diff 191782.
lebedev.ri added a comment.
Keep templated function out of the public interface.
In D59650#1438603 <https://reviews.llvm.org/D59650#1438603>, @JonasToth wrote:
> > Looks like pointless code duplication that is easily avoidable.
>
> True, but I would prefer the refactoring to be private then (so the template stuff with the boilerplate) and a simple overloading interface dispatching to the templated stuff.
> In the end I think the public interface is cleaner, easier to understand and not so easily misused (as the template would accept everything in principle, and SFINAE would be worse).
Right. That looks a bit better. Works for me, thank you!
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59650/new/
https://reviews.llvm.org/D59650
Files:
clang-tidy/utils/ExceptionAnalyzer.cpp
clang-tidy/utils/ExceptionAnalyzer.h
Index: clang-tidy/utils/ExceptionAnalyzer.h
===================================================================
--- clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tidy/utils/ExceptionAnalyzer.h
@@ -138,10 +138,16 @@
throwsException(const Stmt *St, const ExceptionInfo::Throwables &Caught,
llvm::SmallSet<const FunctionDecl *, 32> &CallStack);
+ template <typename T>
+ void analyze(const T *Node, ExceptionInfo &ExceptionList);
+
+ template <typename T> ExceptionInfo analyzeBoilerplate(const T *Node);
+
bool IgnoreBadAlloc = true;
llvm::StringSet<> IgnoredExceptions;
std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;
};
+
} // namespace utils
} // namespace tidy
} // namespace clang
Index: clang-tidy/utils/ExceptionAnalyzer.cpp
===================================================================
--- clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -204,10 +204,9 @@
return Results;
}
-ExceptionAnalyzer::ExceptionInfo
-ExceptionAnalyzer::analyze(const FunctionDecl *Func) {
- ExceptionInfo ExceptionList;
-
+template <>
+void ExceptionAnalyzer::analyze(const FunctionDecl *Func,
+ ExceptionInfo &ExceptionList) {
// Check if the function has already been analyzed and reuse that result.
if (FunctionCache.count(Func) == 0) {
llvm::SmallSet<const FunctionDecl *, 32> CallStack;
@@ -220,6 +219,14 @@
FunctionCache.insert(std::make_pair(Func, ExceptionList));
} else
ExceptionList = FunctionCache[Func];
+}
+
+template <typename T>
+ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyzeBoilerplate(const T *Node) {
+ ExceptionInfo ExceptionList;
+
+ analyze<T>(Node, ExceptionList);
if (ExceptionList.getBehaviour() == State::NotThrowing ||
ExceptionList.getBehaviour() == State::Unknown)
@@ -231,6 +238,12 @@
return ExceptionList;
}
+
+ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyze(const FunctionDecl *Func) {
+ return analyzeBoilerplate(Func);
+}
+
} // namespace utils
} // namespace tidy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59650.191782.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190321/e1e673a7/attachment.bin>
More information about the cfe-commits
mailing list