Cppcheck
|
Classes | |
struct | ConditionState |
Public Types | |
using | ProgramState = ProgramMemory::Map |
Public Types inherited from Analyzer | |
enum class | Terminate { None , Bail , Escape , Modified , Inconclusive , Conditional } |
enum class | Direction { Forward , Reverse } |
enum class | Evaluate { Integral , ContainerEmpty } |
Public Member Functions | |
ValueFlowAnalyzer (const TokenList &t, const Settings &s) | |
virtual const ValueFlow::Value * | getValue (const Token *tok) const =0 |
virtual ValueFlow::Value * | getValue (const Token *tok)=0 |
virtual void | makeConditional ()=0 |
virtual void | addErrorPath (const Token *tok, const std::string &s)=0 |
virtual bool | match (const Token *tok) const =0 |
virtual bool | internalMatch (const Token *) const |
virtual bool | isAlias (const Token *tok, bool &inconclusive) const =0 |
virtual ProgramState | getProgramState () const =0 |
virtual int | getIndirect (const Token *tok) const |
virtual bool | isGlobal () const |
virtual bool | dependsOnThis () const |
virtual bool | isVariable () const |
bool | isCPP () const |
const Settings & | getSettings () const |
Action | analyzeLifetime (const Token *tok) const |
std::unordered_map< nonneg int, const Token * > | getSymbols (const Token *tok) const |
ConditionState | analyzeCondition (const Token *tok, int depth=20) const |
virtual Action | isModified (const Token *tok) const |
virtual Action | isAliasModified (const Token *tok, int indirect=-1) const |
virtual Action | isThisModified (const Token *tok) const |
Action | isGlobalModified (const Token *tok) const |
virtual Action | isWritable (const Token *tok, Direction d) const |
virtual void | writeValue (ValueFlow::Value *value, const Token *tok, Direction d) const |
virtual bool | useSymbolicValues () const |
const Token * | findMatch (const Token *tok) const |
bool | isSameSymbolicValue (const Token *tok, ValueFlow::Value *value=nullptr) const |
Action | analyzeMatch (const Token *tok, Direction d) const |
Action | analyzeToken (const Token *ref, const Token *tok, Direction d, bool inconclusiveRef) const |
Action | analyze (const Token *tok, Direction d) const override |
Analyze a token. More... | |
template<class F > | |
std::vector< MathLib::bigint > | evaluateInt (const Token *tok, F getProgramMemory) const |
std::vector< MathLib::bigint > | evaluateInt (const Token *tok) const |
std::vector< MathLib::bigint > | evaluate (Evaluate e, const Token *tok, const Token *ctx=nullptr) const override |
Try to evaluate the value of a token(most likely a condition) More... | |
void | assume (const Token *tok, bool state, unsigned int flags) override |
The condition that will be assumed during analysis. More... | |
void | updateState (const Token *tok) override |
Update the state of the program at the token. More... | |
virtual void | internalUpdate (Token *, const ValueFlow::Value &, Direction) |
void | update (Token *tok, Action a, Direction d) override |
Update the state of the value. More... | |
ValuePtr< Analyzer > | reanalyze (Token *, const std::string &) const override |
Return analyzer for expression at token. More... | |
Public Member Functions inherited from Analyzer | |
std::vector< MathLib::bigint > | evaluate (const Token *tok, const Token *ctx=nullptr) const |
virtual bool | lowerToPossible ()=0 |
Lower any values to possible. More... | |
virtual bool | lowerToInconclusive ()=0 |
Lower any values to inconclusive. More... | |
virtual bool | updateScope (const Token *endBlock, bool modified) const =0 |
If the analysis is unsure whether to update a scope, this will return true if the analysis should bifurcate the scope. More... | |
virtual bool | isConditional () const =0 |
If the value is conditional. More... | |
virtual bool | stopOnCondition (const Token *condTok) const =0 |
If analysis should stop on the condition. More... | |
virtual bool | invalid () const |
virtual | ~Analyzer ()=default |
Analyzer (const Analyzer &)=default | |
Static Public Member Functions | |
static const std::string & | getAssign (const Token *tok, Direction d) |
Public Attributes | |
const TokenList & | tokenlist |
const Settings & | settings |
ProgramMemoryState | pms |
Additional Inherited Members | |
Protected Member Functions inherited from Analyzer | |
Analyzer ()=default | |
Definition at line 2500 of file valueflow.cpp.
Definition at line 2522 of file valueflow.cpp.
Definition at line 2505 of file valueflow.cpp.
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, and SingleValueFlowAnalyzer.
Referenced by assume().
Analyze a token.
Implements Analyzer.
Definition at line 2978 of file valueflow.cpp.
References analyzeToken(), dependsOnThis(), exprDependsOnThis(), followAllReferences(), Analyzer::Action::Internal, internalMatch(), Analyzer::Action::Invalid, Analyzer::invalid(), isGlobal(), isGlobalModified(), isThisModified(), isVariable(), Token::linkAt(), Token::Match(), Analyzer::Action::None, Token::simpleMatch(), and ReferenceToken::token.
Referenced by analyzeCondition().
|
inline |
Definition at line 2595 of file valueflow.cpp.
References analyze(), Token::astOperand1(), Token::astOperand2(), ValueFlowAnalyzer::ConditionState::dependent, evaluate(), Analyzer::Forward, getArguments(), getSymbols(), Token::hasKnownIntValue(), Analyzer::Integral, isLikelyStream(), Token::isLiteral(), ValueFlowAnalyzer::ConditionState::isUnknownDependent(), Token::Match(), Token::previous(), Token::tokAt(), and ValueFlowAnalyzer::ConditionState::unknown.
Referenced by SingleValueFlowAnalyzer::stopOnCondition().
Definition at line 2552 of file valueflow.cpp.
References astIsRHS(), Token::astOperand1(), Token::astParent(), Analyzer::Action::Match, match(), Analyzer::Action::None, Analyzer::Action::Read, and Token::simpleMatch().
Referenced by analyzeToken().
Definition at line 2905 of file valueflow.cpp.
References astIsPointer(), astIsSmartPointer(), Token::astParent(), dependsOnThis(), getIndirect(), isGlobal(), isGlobalModified(), isModified(), isWritable(), Token::Match(), Token::next(), Analyzer::Action::None, Token::originalName(), Analyzer::Action::Read, and Analyzer::Reverse.
Referenced by analyzeToken().
|
inline |
Definition at line 2924 of file valueflow.cpp.
References analyzeLifetime(), analyzeMatch(), astIsLHS(), Token::astOperand1(), Token::astParent(), Analyzer::Action::Inconclusive, inconclusive, Analyzer::Action::Invalid, isAlias(), isAliasModified(), Analyzer::Action::isInconclusive(), Analyzer::Action::isModified(), isModified(), Analyzer::Action::isRead(), isSameSymbolicValue(), Token::isUnaryOp(), Analyzer::Action::Match, match(), Token::Match(), Analyzer::Action::matches(), Analyzer::Action::None, Analyzer::Action::Read, and Analyzer::Action::SymbolicMatch.
Referenced by analyze().
|
inlineoverridevirtual |
The condition that will be assumed during analysis.
Implements Analyzer.
Definition at line 3056 of file valueflow.cpp.
References Analyzer::Assume::Absolute, addErrorPath(), ProgramMemoryState::addState(), ProgramMemoryState::assume(), Token::astParent(), bool_to_string(), Analyzer::Assume::ContainerEmpty, getProgramState(), Token::link(), Token::linkAt(), makeConditional(), Token::Match(), pms, Token::previous(), Analyzer::Assume::Quiet, ProgramMemoryState::removeModifiedVars(), Token::simpleMatch(), and Token::tokAt().
|
inlinevirtual |
Reimplemented in ExpressionAnalyzer.
Definition at line 2536 of file valueflow.cpp.
Referenced by analyze(), and analyzeMatch().
|
inlineoverridevirtual |
Try to evaluate the value of a token(most likely a condition)
Implements Analyzer.
Definition at line 3034 of file valueflow.cpp.
References Analyzer::ContainerEmpty, evaluateInt(), Token::exprId(), ValueFlow::findValue(), ProgramMemoryState::get(), ProgramMemory::getContainerEmptyValue(), getProgramState(), Analyzer::Integral, ValueFlow::Value::intvalue, pms, settings, and Token::values().
Referenced by analyzeCondition(), and isSameSymbolicValue().
|
inline |
Definition at line 3027 of file valueflow.cpp.
References evaluateInt(), and getProgramState().
|
inline |
Definition at line 3007 of file valueflow.cpp.
References conditionIsFalse(), conditionIsTrue(), error, execute(), getProgramMemory(), getSettings(), Token::hasKnownIntValue(), Token::Match(), and Token::values().
Referenced by evaluate(), evaluateInt(), isModified(), isWritable(), and writeValue().
Definition at line 2848 of file valueflow.cpp.
References findAstNode(), and match().
Referenced by isSameSymbolicValue().
|
inlinestatic |
Definition at line 2745 of file valueflow.cpp.
References Analyzer::Forward, invertAssign(), and Token::str().
Referenced by isWritable(), and writeValue().
|
inlinevirtual |
Reimplemented in ContainerExpressionAnalyzer.
Definition at line 2526 of file valueflow.cpp.
References getValue(), and ValueFlow::Value::indirect.
Referenced by analyzeMatch(), ContainerExpressionAnalyzer::getIndirect(), and isModified().
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, and ExpressionAnalyzer.
Referenced by assume(), evaluate(), evaluateInt(), and updateState().
|
inline |
Definition at line 2547 of file valueflow.cpp.
References settings.
Referenced by evaluateInt(), isAliasModified(), isGlobalModified(), isModified(), ContainerExpressionAnalyzer::isModified(), isThisModified(), SameExpressionAnalyzer::match(), OppositeExpressionAnalyzer::match(), update(), SingleValueFlowAnalyzer::updateScope(), and MultiValueFlowAnalyzer::updateScope().
|
inline |
Definition at line 2574 of file valueflow.cpp.
References match(), and Token::values().
Referenced by analyzeCondition().
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, and SingleValueFlowAnalyzer.
Referenced by getIndirect(), isModified(), isSameSymbolicValue(), isWritable(), and update().
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, and SingleValueFlowAnalyzer.
|
inlinevirtual |
Reimplemented in SubExpressionAnalyzer.
Definition at line 2516 of file valueflow.cpp.
Referenced by analyze().
|
inlinevirtual |
Reimplemented in SubExpressionAnalyzer.
Definition at line 3102 of file valueflow.cpp.
Referenced by update().
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, SubExpressionAnalyzer, and SingleValueFlowAnalyzer.
Referenced by analyzeToken().
|
inlinevirtual |
Reimplemented in ExpressionAnalyzer.
Definition at line 2700 of file valueflow.cpp.
References getSettings(), Analyzer::Action::Invalid, isVariableChanged(), ValueType::ITERATOR, Token::Match(), Analyzer::Action::None, and Token::valueType().
Referenced by analyzeToken(), and ExpressionAnalyzer::isAliasModified().
|
inline |
Definition at line 2543 of file valueflow.cpp.
References TokenList::isCPP(), and tokenlist.
|
inlinevirtual |
Reimplemented in ExpressionAnalyzer, and SingleValueFlowAnalyzer.
Definition at line 2533 of file valueflow.cpp.
Referenced by analyze(), and analyzeMatch().
Definition at line 2725 of file valueflow.cpp.
References astIsContainer(), astIsPrimitive(), Token::astParent(), Token::eType, Token::function(), getSettings(), Analyzer::Action::Invalid, isConstFunctionCall(), Token::isKeyword(), Token::Match(), Token::next(), Analyzer::Action::None, Token::simpleMatch(), and Token::tokType().
Referenced by analyze(), and analyzeMatch().
Reimplemented in ContainerExpressionAnalyzer.
Definition at line 2665 of file valueflow.cpp.
References astContainerAction(), astIsContainer(), astIsIntegral(), astIsLHS(), Token::astParent(), Library::Container::CHANGE_INTERNAL, contains(), ValueFlow::Value::equalTo(), evaluateInt(), getIndirect(), getSettings(), getValue(), Analyzer::Action::Idempotent, Analyzer::Action::Inconclusive, inconclusive, Library::Container::INSERT, Analyzer::Action::Invalid, ValueFlow::Value::isImpossible(), ValueFlow::Value::isLifetimeValue(), ValueFlow::Value::isMovedValue(), isMoveOrForward(), isVariableChanged(), isVariableChangedByFunctionCall(), Token::Match(), ValueFlow::Value::NonMovedVariable, Library::Container::PUSH, Analyzer::Action::Read, and Token::simpleMatch().
Referenced by analyzeMatch(), and analyzeToken().
|
inline |
Definition at line 2855 of file valueflow.cpp.
References ValueFlow::Value::bound, ValueFlow::Value::equalValue(), ValueFlow::Value::errorPath, evaluate(), findMatch(), getValue(), Analyzer::Integral, ValueFlow::Value::intvalue, ValueFlow::Value::isImpossible(), ValueFlow::Value::isIntValue(), ValueFlow::Value::isKnown(), ValueFlow::Value::isSymbolicValue(), match(), Token::Match(), ValueFlow::Value::Point, ValueFlow::Value::setImpossible(), ValueFlow::Value::tokvalue, useSymbolicValues(), and Token::values().
Referenced by analyzeToken(), and update().
Definition at line 2719 of file valueflow.cpp.
References getSettings(), Analyzer::Action::Invalid, isThisChanged(), and Analyzer::Action::None.
Referenced by analyze().
|
inlinevirtual |
Reimplemented in ExpressionAnalyzer.
Definition at line 2539 of file valueflow.cpp.
Referenced by analyze().
Reimplemented in ContainerExpressionAnalyzer.
Definition at line 2752 of file valueflow.cpp.
References astIsLHS(), Token::astOperand2(), Token::astParent(), ValueFlow::Value::equalValue(), evalAssignment(), evaluateInt(), Token::exprId(), findAstNode(), getAssign(), getValue(), Analyzer::Action::Idempotent, Analyzer::Action::Incremental, Analyzer::Action::Invalid, Token::isAssignmentOp(), ValueFlow::Value::isFloatValue(), ValueFlow::Value::isImpossible(), ValueFlow::Value::isIntValue(), ValueFlow::Value::isLifetimeValue(), ValueFlow::Value::isSymbolicValue(), ValueFlow::Value::Iterator, ValueFlow::Value::lifetimeKind, Token::Match(), Analyzer::Action::None, Analyzer::Action::Read, Token::str(), and Analyzer::Action::Write.
Referenced by analyzeMatch().
|
pure virtual |
Implemented in MultiValueFlowAnalyzer, and SingleValueFlowAnalyzer.
Referenced by assume().
|
pure virtual |
Implemented in ContainerExpressionAnalyzer, MultiValueFlowAnalyzer, SubExpressionAnalyzer, OppositeExpressionAnalyzer, SameExpressionAnalyzer, and ExpressionAnalyzer.
Referenced by analyzeLifetime(), analyzeToken(), findMatch(), getSymbols(), and isSameSymbolicValue().
|
inlineoverridevirtual |
Return analyzer for expression at token.
Implements Analyzer.
Reimplemented in SingleValueFlowAnalyzer, and SubExpressionAnalyzer.
Definition at line 3133 of file valueflow.cpp.
Update the state of the value.
Implements Analyzer.
Definition at line 3107 of file valueflow.cpp.
References Token::astParent(), Analyzer::Forward, getSettings(), getValue(), internalUpdate(), Analyzer::Action::isInconclusive(), Analyzer::Action::isInternal(), Analyzer::Action::isRead(), isSameSymbolicValue(), Analyzer::Action::isSymbolicMatch(), Analyzer::Action::isWrite(), Analyzer::lowerToInconclusive(), Analyzer::Reverse, setTokenValue(), and writeValue().
|
inlineoverridevirtual |
Update the state of the program at the token.
Implements Analyzer.
Definition at line 3095 of file valueflow.cpp.
References ProgramMemoryState::addState(), getProgramState(), pms, and ProgramMemoryState::removeModifiedVars().
|
inlinevirtual |
Reimplemented in SingleValueFlowAnalyzer.
Definition at line 2844 of file valueflow.cpp.
Referenced by isSameSymbolicValue().
|
inlinevirtual |
Reimplemented in ContainerExpressionAnalyzer.
Definition at line 2801 of file valueflow.cpp.
References Token::astParent(), Token::eIncDecOp, ValueFlow::Value::errorPath, evalAssignment(), evaluateInt(), getAssign(), ValueFlow::getSizeOf(), ValueFlow::Value::infoString(), ValueFlow::Value::intvalue, ValueFlow::Value::isLifetimeValue(), Analyzer::Reverse, settings, ValueType::sign, Token::str(), truncateIntValue(), and Token::valueType().
Referenced by update().
ProgramMemoryState ValueFlowAnalyzer::pms |
Definition at line 2503 of file valueflow.cpp.
Referenced by assume(), evaluate(), and updateState().
const Settings& ValueFlowAnalyzer::settings |
Definition at line 2502 of file valueflow.cpp.
Referenced by evaluate(), getSettings(), SingleValueFlowAnalyzer::reanalyze(), and writeValue().
const TokenList& ValueFlowAnalyzer::tokenlist |
Definition at line 2501 of file valueflow.cpp.
Referenced by isCPP(), and SingleValueFlowAnalyzer::reanalyze().