clang-tools 22.0.0git
clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo Class Reference

Bundle the gathered information about an entity like a function regarding it's exception behaviour. More...

#include <ExceptionAnalyzer.h>

Classes

struct  ThrowInfo
 Holds information about where an exception is thrown. More...

Public Types

using Throwables = llvm::SmallDenseMap<const Type *, ThrowInfo, 2>

Public Member Functions

 ExceptionInfo ()
 By default the exception situation is unknown and must be clarified step-wise.
 ExceptionInfo (State S)
 ExceptionInfo (const ExceptionInfo &)=default
ExceptionInfooperator= (const ExceptionInfo &)=default
 ExceptionInfo (ExceptionInfo &&)=default
ExceptionInfooperator= (ExceptionInfo &&)=default
State getBehaviour () const
void registerException (const Type *ExceptionType, const ThrowInfo &ThrowInfo)
 Register a single exception type as recognized potential exception to be thrown.
void registerExceptions (const Throwables &Exceptions)
 Registers a SmallVector of exception types as recognized potential exceptions to be thrown.
ExceptionInfomerge (const ExceptionInfo &Other)
 Updates the local state according to the other state.
Throwables filterByCatch (const Type *HandlerTy, const ASTContext &Context)
 This method is useful in case 'catch' clauses are analyzed as it is possible to catch multiple exception types by one 'catch' if they are a subclass of the 'catch'ed exception type.
ExceptionInfofilterIgnoredExceptions (const llvm::StringSet<> &IgnoredTypes, bool IgnoreBadAlloc)
 Filter the set of thrown exception type against a set of ignored types that shall not be considered in the exception analysis.
void clear ()
 Clear the state to 'NonThrowing' to make the corresponding entity neutral.
const ThrowablesgetExceptions () const
 References the set of known exceptions that can escape from the corresponding entity.
bool containsUnknownElements () const
 Signal if the there is any 'Unknown' element within the scope of the related entity.

Static Public Member Functions

static ExceptionInfo createUnknown ()
static ExceptionInfo createNonThrowing ()

Detailed Description

Bundle the gathered information about an entity like a function regarding it's exception behaviour.

The 'NonThrowing'-state can be considered as the neutral element in terms of information propagation. In the case of 'Throwing' state it is possible that 'getExceptionTypes' does not include ALL possible types as there is the possibility that an 'Unknown' function is called that might throw a previously unknown exception at runtime.

Definition at line 43 of file ExceptionAnalyzer.h.

Member Typedef Documentation

◆ Throwables

using clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::Throwables = llvm::SmallDenseMap<const Type *, ThrowInfo, 2>

Definition at line 52 of file ExceptionAnalyzer.h.

Constructor & Destructor Documentation

◆ ExceptionInfo() [1/4]

clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::ExceptionInfo ( )
inline

By default the exception situation is unknown and must be clarified step-wise.

Definition at line 59 of file ExceptionAnalyzer.h.

References clang::tidy::utils::ExceptionAnalyzer::NotThrowing.

Referenced by createNonThrowing(), createUnknown(), ExceptionInfo(), ExceptionInfo(), operator=(), and operator=().

◆ ExceptionInfo() [2/4]

clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::ExceptionInfo ( State S)
inline

◆ ExceptionInfo() [3/4]

clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::ExceptionInfo ( const ExceptionInfo & )
default

References ExceptionInfo().

◆ ExceptionInfo() [4/4]

clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::ExceptionInfo ( ExceptionInfo && )
default

References ExceptionInfo().

Member Function Documentation

◆ clear()

void clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::clear ( )

Clear the state to 'NonThrowing' to make the corresponding entity neutral.

Definition at line 452 of file ExceptionAnalyzer.cpp.

References clang::tidy::utils::ExceptionAnalyzer::NotThrowing.

◆ containsUnknownElements()

bool clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::containsUnknownElements ( ) const
inline

Signal if the there is any 'Unknown' element within the scope of the related entity.

This might be relevant if the entity is 'Throwing' and to ensure that no other exception then 'getExceptionTypes' can occur. If there is an 'Unknown' element this can not be guaranteed.

Definition at line 112 of file ExceptionAnalyzer.h.

◆ createNonThrowing()

ExceptionInfo clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::createNonThrowing ( )
inlinestatic

◆ createUnknown()

ExceptionInfo clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::createUnknown ( )
inlinestatic

◆ filterByCatch()

ExceptionAnalyzer::ExceptionInfo::Throwables clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::filterByCatch ( const Type * HandlerTy,
const ASTContext & Context )

This method is useful in case 'catch' clauses are analyzed as it is possible to catch multiple exception types by one 'catch' if they are a subclass of the 'catch'ed exception type.

Returns filtered exceptions.

Definition at line 360 of file ExceptionAnalyzer.cpp.

◆ filterIgnoredExceptions()

ExceptionAnalyzer::ExceptionInfo & clang::tidy::utils::ExceptionAnalyzer::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 in the exception analysis.

This includes explicit std::bad_alloc ignoring as separate option.

Definition at line 429 of file ExceptionAnalyzer.cpp.

◆ getBehaviour()

State clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::getBehaviour ( ) const
inline

Definition at line 68 of file ExceptionAnalyzer.h.

◆ getExceptions()

const Throwables & clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::getExceptions ( ) const
inline

References the set of known exceptions that can escape from the corresponding entity.

Definition at line 106 of file ExceptionAnalyzer.h.

◆ merge()

ExceptionAnalyzer::ExceptionInfo & clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::merge ( const ExceptionInfo & Other)

Updates the local state according to the other state.

That means if for example a function contains multiple statements the 'ExceptionInfo' for the final function is the merged result of each statement. If one of these statements throws the whole function throws and if one part is unknown and the rest is non-throwing the result will be unknown.

Definition at line 28 of file ExceptionAnalyzer.cpp.

References clang::tidy::utils::ExceptionAnalyzer::NotThrowing, clang::tidy::utils::ExceptionAnalyzer::Throwing, and clang::tidy::utils::ExceptionAnalyzer::Unknown.

◆ operator=() [1/2]

ExceptionInfo & clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::operator= ( const ExceptionInfo & )
default

References ExceptionInfo().

◆ operator=() [2/2]

ExceptionInfo & clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::operator= ( ExceptionInfo && )
default

References ExceptionInfo().

◆ registerException()

void clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::registerException ( const Type * ExceptionType,
const ThrowInfo & ThrowInfo )

Register a single exception type as recognized potential exception to be thrown.

Definition at line 13 of file ExceptionAnalyzer.cpp.

References clang::tidy::utils::ExceptionAnalyzer::Throwing.

◆ registerExceptions()

void clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::registerExceptions ( const Throwables & Exceptions)

Registers a SmallVector of exception types as recognized potential exceptions to be thrown.

Definition at line 20 of file ExceptionAnalyzer.cpp.

References clang::tidy::utils::ExceptionAnalyzer::Throwing.


The documentation for this class was generated from the following files: