clang-tools 10.0.0

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. More...
| ExceptionInfo (State S)
| ExceptionInfo (const ExceptionInfo &)=default
ExceptionInfo & | operator= (const ExceptionInfo &)=default
| ExceptionInfo (ExceptionInfo &&)=default
ExceptionInfo & | operator= (ExceptionInfo &&)=default
State | getBehaviour () const
void | registerException (const Type *ExceptionType)
| Register a single exception type as recognized potential exception to be thrown. More...
void | registerExceptions (const Throwables &Exceptions)
| Registers a `SmallVector` of exception types as recognized potential exceptions to be thrown. More...
ExceptionInfo & | merge (const ExceptionInfo &Other)
| Updates the local state according to the other state. More...
bool | filterByCatch (const Type *BaseClass)
| 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. More...
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. More...
void | clear ()
| Clear the state to 'NonThrowing' to make the corresponding entity neutral. More...
const Throwables & | getExceptionTypes () const
| References the set of known exception types that can escape from the corresponding entity. More...
bool | containsUnknownElements () const
| Signal if the there is any 'Unknown' element within the scope of the related entity. More...

## 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 40 of file ExceptionAnalyzer.h.

## Member Typedef Documentation

## ◆ Throwables

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

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

## ◆ ExceptionInfo() [2/4]

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

Definition at line 53 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 96 of file ExceptionAnalyzer.cpp.

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

## ◆ 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 104 of file ExceptionAnalyzer.h.

References clang::tidy::utils::ExceptionAnalyzer::ExceptionAnalyzer().

## ◆ createNonThrowing()

static ExceptionInfo clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::createNonThrowing | ( |  | ) |
| inline static

Definition at line 46 of file ExceptionAnalyzer.h.

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

Referenced by clear().

## ◆ createUnknown()

static ExceptionInfo clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::createUnknown | ( |  | ) |
| inline static

Definition at line 43 of file ExceptionAnalyzer.h.

References clang::tidy::utils::ExceptionAnalyzer::Unknown.

## ◆ filterByCatch()

bool clang::tidy::utils::ExceptionAnalyzer::ExceptionInfo::filterByCatch | ( | const Type * | BaseClass | ) |

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

References clang::tidy::utils::isBaseOf(), and 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 74 of file ExceptionAnalyzer.cpp.

References Type.

## ◆ getBehaviour()

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

Definition at line 61 of file ExceptionAnalyzer.h.

References Type.

## ◆ 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 98 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 30 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 15 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 22 of file ExceptionAnalyzer.cpp.

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

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

- ExceptionAnalyzer.h
- ExceptionAnalyzer.cpp