Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 #include "llvm/ADT/SmallSet.h"
15 #include "llvm/ADT/StringSet.h"
26 enum class State : std::int8_t {
54 : Behaviour(S), ContainsUnknown(S ==
State::Unknown) {}
108 void reevaluateBehaviour();
117 bool ContainsUnknown;
128 IgnoredExceptions = std::move(ExceptionNames);
131 ExceptionInfo
analyze(
const FunctionDecl *Func);
132 ExceptionInfo
analyze(
const Stmt *Stmt);
136 throwsException(
const FunctionDecl *Func,
137 llvm::SmallSet<const FunctionDecl *, 32> &CallStack);
140 llvm::SmallSet<const FunctionDecl *, 32> &CallStack);
142 ExceptionInfo analyzeImpl(
const FunctionDecl *Func);
143 ExceptionInfo analyzeImpl(
const Stmt *Stmt);
145 template <
typename T> ExceptionInfo analyzeDispatch(
const T *Node);
147 bool IgnoreBadAlloc =
true;
148 llvm::StringSet<> IgnoredExceptions;
149 std::map<const FunctionDecl *, ExceptionInfo> FunctionCache;
156 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_ANALYZER_H
ExceptionInfo & merge(const ExceptionInfo &Other)
Updates the local state according to the other state.
void clear()
Clear the state to 'NonThrowing' to make the corresponding entity neutral.
ExceptionAnalyzer()=default
static ExceptionInfo createNonThrowing()
void ignoreBadAlloc(bool ShallIgnore)
void ignoreExceptions(llvm::StringSet<> ExceptionNames)
This class analysis if a FunctionDecl can in principle throw an exception, either directly or indirec...
bool containsUnknownElements() const
Signal if the there is any 'Unknown' element within the scope of the related entity.
This function can not throw, given an AST.
State getBehaviour() const
llvm::SmallSet< const Type *, 2 > Throwables
void registerException(const Type *ExceptionType)
Register a single exception type as recognized potential exception to be thrown.
This can happen for extern functions without available definition.
void registerExceptions(const Throwables &Exceptions)
Registers a SmallVector of exception types as recognized potential exceptions to be thrown.
const Throwables & getExceptionTypes() const
References the set of known exception types that can escape from the corresponding entity.
ExceptionInfo & filterIgnoredExceptions(const llvm::StringSet<> &IgnoredTypes, bool IgnoreBadAlloc)
Filter the set of thrown exception type against a set of ignored types that shall not be considered i...
static ExceptionInfo createUnknown()
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
The function can definitely throw given an AST.
ExceptionInfo analyze(const FunctionDecl *Func)
bool filterByCatch(const Type *BaseClass)
This method is useful in case 'catch' clauses are analyzed as it is possible to catch multiple except...
Bundle the gathered information about an entity like a function regarding it's exception behaviour.
ExceptionInfo & operator=(const ExceptionInfo &)=default
ExceptionInfo()
By default the exception situation is unknown and must be clarified step-wise.