MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowSymbolicInfer

Function valueFlowSymbolicInfer

lib/valueflow.cpp:3767–3806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3765};
3766
3767static void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const Settings& settings)
3768{
3769 for (const Scope* scope : symboldatabase.functionScopes) {
3770 for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
3771 if (!Token::Match(tok, "-|%comp%"))
3772 continue;
3773 if (tok->hasKnownIntValue())
3774 continue;
3775 if (!tok->astOperand1())
3776 continue;
3777 if (!tok->astOperand2())
3778 continue;
3779 if (tok->astOperand1()->exprId() == 0)
3780 continue;
3781 if (tok->astOperand2()->exprId() == 0)
3782 continue;
3783 if (tok->astOperand1()->hasKnownIntValue())
3784 continue;
3785 if (tok->astOperand2()->hasKnownIntValue())
3786 continue;
3787 if (astIsFloat(tok->astOperand1(), false))
3788 continue;
3789 if (astIsFloat(tok->astOperand2(), false))
3790 continue;
3791
3792 std::vector<ValueFlow::Value> values;
3793 {
3794 SymbolicInferModel leftModel{tok->astOperand1()};
3795 values = infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
3796 }
3797 if (values.empty()) {
3798 SymbolicInferModel rightModel{tok->astOperand2()};
3799 values = infer(rightModel, tok->str(), tok->astOperand1()->values(), 0);
3800 }
3801 for (ValueFlow::Value& value : values) {
3802 setTokenValue(tok, std::move(value), settings);
3803 }
3804 }
3805 }
3806}
3807
3808/**
3809 * @throws InternalError thrown if start token precedes end token

Callers 1

setValuesMethod · 0.85

Calls 9

inferFunction · 0.85
setTokenValueFunction · 0.85
nextMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
astIsFloatFunction · 0.70
hasKnownIntValueMethod · 0.45
strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected