clang-tools 19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
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>

Public Types

using Throwables = llvm::SmallSet< const Type *, 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)
 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.
 
bool 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 ThrowablesgetExceptionTypes () const
 References the set of known exception types 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 38 of file ExceptionAnalyzer.h.

Member Typedef Documentation

◆ Throwables

Definition at line 40 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 46 of file ExceptionAnalyzer.h.

◆ ExceptionInfo() [2/4]

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

Definition at line 47 of file ExceptionAnalyzer.h.

◆ ExceptionInfo() [3/4]

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

◆ ExceptionInfo() [4/4]

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

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 433 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 98 of file ExceptionAnalyzer.h.

◆ createNonThrowing()

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

◆ createUnknown()

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

◆ filterByCatch()

bool 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 'true' if some exceptions were filtered, otherwise 'false'.

Definition at line 347 of file ExceptionAnalyzer.cpp.

References Type.

◆ 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 411 of file ExceptionAnalyzer.cpp.

References Type.

◆ getBehaviour()

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

Definition at line 55 of file ExceptionAnalyzer.h.

◆ getExceptionTypes()

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

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

Definition at line 92 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

◆ operator=() [2/2]

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

◆ registerException()

void clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::registerException ( const Type ExceptionType)

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: