Cppcheck
|
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 Token * | reassign (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 Settings & | mSettings |
enum FwdAnalysis::What | mWhat = What::Reassign |
std::vector< KnownAndToken > | mValueFlow |
bool | mValueFlowKnown = true |
Forward data flow analysis for checks.
Definition at line 38 of file fwdanalysis.h.
|
strongprivate |
Enumerator | |
---|---|
Reassign | |
UnusedValue | |
ValueFlow |
Definition at line 86 of file fwdanalysis.h.
|
inlineexplicit |
Definition at line 40 of file fwdanalysis.h.
|
private |
Definition at line 433 of file fwdanalysis.cpp.
References FwdAnalysis::Result::BAILOUT, FwdAnalysis::Result::BREAK, checkRecursive(), findNextTokenFromBreak(), getExprVarIds(), isGlobalData(), mWhat, Token::next(), Reassign, FwdAnalysis::Result::token, FwdAnalysis::Result::type, UnusedValue, and ValueFlow.
Referenced by reassign(), and unusedValue().
|
private |
Definition at line 96 of file fwdanalysis.cpp.
References Library::Function::argumentChecks, Token::astOperand1(), Token::astOperand2(), Token::astParent(), FwdAnalysis::Result::BAILOUT, FwdAnalysis::Result::BREAK, Library::ArgumentChecks::DIR_OUT, Token::eLambda, Token::findExpressionStartEndTokens(), findLambdaEndToken(), findNextTokenFromBreak(), getArguments(), Library::getFunction(), hasFunctionCall(), hasGccCompoundStatement(), Token::hasKnownIntValue(), hasOperand(), Token::isCast(), Token::isName(), isReturnScope(), isSameExpression(), Token::isUnaryOp(), isUnchanged(), FwdAnalysis::KnownAndToken::known, Settings::library, Token::link(), Token::linkAt(), Token::Match(), mSettings, mValueFlow, mValueFlowKnown, mWhat, Token::next(), FwdAnalysis::Result::NONE, None, ValueType::pointer, precedes(), Token::previous(), FwdAnalysis::Result::READ, reassign(), Reassign, ValueType::reference, FwdAnalysis::Result::RETURN, Token::scope(), Token::simpleMatch(), Token::str(), Token::tokAt(), FwdAnalysis::KnownAndToken::token, FwdAnalysis::Result::token, FwdAnalysis::Result::type, UnusedValue, ValueFlow, Token::values(), Token::valueType(), Token::variable(), Token::varId(), and FwdAnalysis::Result::WRITE.
Referenced by check().
std::set< nonneg int > FwdAnalysis::getExprVarIds | ( | const Token * | expr, |
bool * | localOut = nullptr , |
||
bool * | unknownVarIdOut = nullptr |
||
) | const |
Definition at line 399 of file fwdanalysis.cpp.
References Token::isName(), mWhat, op1, op1_and_op2, Token::previous(), Token::str(), UnusedValue, Token::varId(), and visitAstNodes().
Referenced by check().
Definition at line 464 of file fwdanalysis.cpp.
References Token::astOperand1(), Token::astOperand2(), isSameExpression(), and mSettings.
Referenced by checkRecursive(), and CheckOther::checkRedundantAssignment().
|
staticprivate |
Definition at line 550 of file fwdanalysis.cpp.
References Token::astOperand1(), Variable::isArgument(), and Variable::isLocal().
Referenced by unusedValue().
Is there some possible alias for given expression.
Definition at line 495 of file fwdanalysis.cpp.
References Token::astOperand1(), Token::astOperand2(), getArguments(), isSameExpression(), Token::isUnaryOp(), Token::Match(), mSettings, Token::previous(), Token::scope(), Token::simpleMatch(), Token::str(), Token::tokAt(), Token::varId(), and Scope::varlist.
Referenced by unusedValue().
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]).
expr | Symbolic expression to perform forward analysis for |
startToken | First token in forward analysis |
endToken | Last token in forward analysis |
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().
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]).
expr | Symbolic expression to perform forward analysis for |
startToken | First token in forward analysis |
endToken | Last token in forward analysis |
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().
|
private |
Definition at line 85 of file fwdanalysis.h.
Referenced by checkRecursive(), hasOperand(), and possiblyAliased().
|
private |
Definition at line 87 of file fwdanalysis.h.
Referenced by checkRecursive().
|
private |
Definition at line 88 of file fwdanalysis.h.
Referenced by checkRecursive().
|
private |
Referenced by check(), checkRecursive(), getExprVarIds(), reassign(), and unusedValue().