Cppcheck
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
FwdAnalysis Class Reference

Forward data flow analysis for checks. More...

#include <fwdanalysis.h>

Classes

struct  KnownAndToken
 
struct  Result
 Result of forward analysis. More...
 

Public Member Functions

 FwdAnalysis (const Settings &settings)
 
bool hasOperand (const Token *tok, const Token *lhs) const
 
const Tokenreassign (const Token *expr, const Token *startToken, const Token *endToken)
 Check if "expr" is reassigned. More...
 
bool unusedValue (const Token *expr, const Token *startToken, const Token *endToken)
 Check if "expr" is used. More...
 
bool possiblyAliased (const Token *expr, const Token *startToken) const
 Is there some possible alias for given expression. More...
 
std::set< nonneg int > getExprVarIds (const Token *expr, bool *localOut=nullptr, bool *unknownVarIdOut=nullptr) const
 

Private Types

enum class  What { Reassign , UnusedValue , ValueFlow }
 

Private Member Functions

Result check (const Token *expr, const Token *startToken, const Token *endToken)
 
Result checkRecursive (const Token *expr, const Token *startToken, const Token *endToken, const std::set< nonneg int > &exprVarIds, bool local, bool inInnerClass, int depth=0)
 

Static Private Member Functions

static bool isEscapedAlias (const Token *expr)
 

Private Attributes

const SettingsmSettings
 
enum FwdAnalysis::What mWhat = What::Reassign
 
std::vector< KnownAndTokenmValueFlow
 
bool mValueFlowKnown = true
 

Detailed Description

Forward data flow analysis for checks.

Definition at line 38 of file fwdanalysis.h.

Member Enumeration Documentation

◆ What

enum FwdAnalysis::What
strongprivate
Enumerator
Reassign 
UnusedValue 
ValueFlow 

Definition at line 86 of file fwdanalysis.h.

Constructor & Destructor Documentation

◆ FwdAnalysis()

FwdAnalysis::FwdAnalysis ( const Settings settings)
inlineexplicit

Definition at line 40 of file fwdanalysis.h.

Member Function Documentation

◆ check()

FwdAnalysis::Result FwdAnalysis::check ( const Token expr,
const Token startToken,
const Token endToken 
)
private

◆ checkRecursive()

FwdAnalysis::Result FwdAnalysis::checkRecursive ( const Token expr,
const Token startToken,
const Token endToken,
const std::set< nonneg int > &  exprVarIds,
bool  local,
bool  inInnerClass,
int  depth = 0 
)
private

◆ getExprVarIds()

std::set< nonneg int > FwdAnalysis::getExprVarIds ( const Token expr,
bool *  localOut = nullptr,
bool *  unknownVarIdOut = nullptr 
) const

◆ hasOperand()

bool FwdAnalysis::hasOperand ( const Token tok,
const Token lhs 
) const

◆ isEscapedAlias()

bool FwdAnalysis::isEscapedAlias ( const Token expr)
staticprivate

Definition at line 550 of file fwdanalysis.cpp.

References Token::astOperand1(), Variable::isArgument(), and Variable::isLocal().

Referenced by unusedValue().

◆ possiblyAliased()

bool FwdAnalysis::possiblyAliased ( const Token expr,
const Token startToken 
) const

◆ reassign()

const Token * FwdAnalysis::reassign ( const Token expr,
const Token startToken,
const Token endToken 
)

Check if "expr" is reassigned.

The "expr" can be a tree (x.y[12]).

Parameters
exprSymbolic expression to perform forward analysis for
startTokenFirst token in forward analysis
endTokenLast token in forward analysis
Returns
Token where expr is reassigned. If it's not reassigned then nullptr is returned.

Definition at line 473 of file fwdanalysis.cpp.

References check(), hasVolatileCastOrVar(), mWhat, Reassign, FwdAnalysis::Result::token, FwdAnalysis::Result::type, and FwdAnalysis::Result::WRITE.

Referenced by checkRecursive(), and CheckOther::checkRedundantAssignment().

◆ unusedValue()

bool FwdAnalysis::unusedValue ( const Token expr,
const Token startToken,
const Token endToken 
)

Check if "expr" is used.

The "expr" can be a tree (x.y[12]).

Parameters
exprSymbolic expression to perform forward analysis for
startTokenFirst token in forward analysis
endTokenLast token in forward analysis
Returns
true if expr is used.

Definition at line 482 of file fwdanalysis.cpp.

References astIsContainerView(), Token::astOperand1(), check(), hasVolatileCastOrVar(), isEscapedAlias(), mWhat, FwdAnalysis::Result::NONE, possiblyAliased(), FwdAnalysis::Result::RETURN, Token::simpleMatch(), FwdAnalysis::Result::type, and UnusedValue.

Referenced by CheckUnusedVar::checkFunctionVariableUsage().

Member Data Documentation

◆ mSettings

const Settings& FwdAnalysis::mSettings
private

Definition at line 85 of file fwdanalysis.h.

Referenced by checkRecursive(), hasOperand(), and possiblyAliased().

◆ mValueFlow

std::vector<KnownAndToken> FwdAnalysis::mValueFlow
private

Definition at line 87 of file fwdanalysis.h.

Referenced by checkRecursive().

◆ mValueFlowKnown

bool FwdAnalysis::mValueFlowKnown = true
private

Definition at line 88 of file fwdanalysis.h.

Referenced by checkRecursive().

◆ mWhat

enum FwdAnalysis::What FwdAnalysis::mWhat = What::Reassign
private

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