Cppcheck
|
#include "programmemory.h"
#include "astutils.h"
#include "calculate.h"
#include "infer.h"
#include "library.h"
#include "mathlib.h"
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include "utils.h"
#include "valueflow.h"
#include "valueptr.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iterator>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include <vector>
Go to the source code of this file.
Typedefs | |
using | BuiltinLibraryFunction = std::function< ValueFlow::Value(const std::vector< ValueFlow::Value > &)> |
Functions | |
static ValueFlow::Value | execute (const Token *expr, ProgramMemory &pm, const Settings &settings) |
static bool | evaluateCondition (MathLib::bigint r, const Token *condition, ProgramMemory &pm, const Settings &settings) |
bool | conditionIsFalse (const Token *condition, ProgramMemory pm, const Settings &settings) |
Is condition always false when variable has given value? More... | |
bool | conditionIsTrue (const Token *condition, ProgramMemory pm, const Settings &settings) |
Is condition always true when variable has given value? More... | |
static bool | frontIs (const std::vector< MathLib::bigint > &v, bool i) |
static bool | isTrue (const ValueFlow::Value &v) |
static bool | isFalse (const ValueFlow::Value &v) |
static bool | isTrueOrFalse (const ValueFlow::Value &v, bool b) |
static bool | isBasicForLoop (const Token *tok) |
static void | programMemoryParseCondition (ProgramMemory &pm, const Token *tok, const Token *endTok, const Settings &settings, bool then) |
static void | fillProgramMemoryFromConditions (ProgramMemory &pm, const Scope *scope, const Token *endTok, const Settings &settings) |
static void | fillProgramMemoryFromConditions (ProgramMemory &pm, const Token *tok, const Settings &settings) |
static void | fillProgramMemoryFromAssignments (ProgramMemory &pm, const Token *tok, const Settings &settings, const ProgramMemory &state, const ProgramMemory::Map &vars) |
static void | removeModifiedVars (ProgramMemory &pm, const Token *tok, const Token *origin, const Settings &settings) |
static ProgramMemory | getInitialProgramState (const Token *tok, const Token *origin, const Settings &settings, const ProgramMemory::Map &vars=ProgramMemory::Map {}) |
static void | addVars (ProgramMemory &pm, const ProgramMemory::Map &vars) |
ProgramMemory | getProgramMemory (const Token *tok, const Token *expr, const ValueFlow::Value &value, const Settings &settings) |
Get program memory by looking backwards from given token. More... | |
static bool | isNumericValue (const ValueFlow::Value &value) |
static double | asFloat (const ValueFlow::Value &value) |
static std::string | removeAssign (const std::string &assign) |
static bool | isIntegralValue (const ValueFlow::Value &value) |
static ValueFlow::Value | evaluate (const std::string &op, const ValueFlow::Value &lhs, const ValueFlow::Value &rhs) |
static std::unordered_map< std::string, BuiltinLibraryFunction > | createBuiltinLibraryFunctions () |
static BuiltinLibraryFunction | getBuiltinLibraryFunction (const std::string &name) |
static bool | TokenExprIdCompare (const Token *tok1, const Token *tok2) |
static bool | TokenExprIdEqual (const Token *tok1, const Token *tok2) |
static std::vector< const Token * > | setDifference (const std::vector< const Token * > &v1, const std::vector< const Token * > &v2) |
static bool | evalSameCondition (const ProgramMemory &state, const Token *storedValue, const Token *cond, const Settings &settings) |
static void | pruneConditions (std::vector< const Token * > &conds, bool b, const std::unordered_map< nonneg int, ValueFlow::Value > &state) |
std::vector< ValueFlow::Value > | execute (const Scope *scope, ProgramMemory &pm, const Settings &settings) |
ValueFlow::Value | evaluateLibraryFunction (const std::unordered_map< nonneg int, ValueFlow::Value > &args, const std::string &returnValue, const Settings &settings, bool cpp) |
void | execute (const Token *expr, ProgramMemory &programMemory, MathLib::bigint *result, bool *error, const Settings &settings) |
using BuiltinLibraryFunction = std::function<ValueFlow::Value(const std::vector<ValueFlow::Value>&)> |
Definition at line 647 of file programmemory.cpp.
|
static |
Definition at line 463 of file programmemory.cpp.
References ProgramMemory::setValue().
Referenced by ProgramMemoryState::addState().
|
static |
Definition at line 555 of file programmemory.cpp.
References ValueFlow::Value::floatValue, ValueFlow::Value::intvalue, and ValueFlow::Value::isFloatValue().
Referenced by evaluate().
bool conditionIsFalse | ( | const Token * | condition, |
ProgramMemory | pm, | ||
const Settings & | settings | ||
) |
Is condition always false when variable has given value?
condition | top ast token in condition |
pm | program memory |
Definition at line 211 of file programmemory.cpp.
References evaluateCondition().
Referenced by ValueFlowAnalyzer::evaluateInt(), fillProgramMemoryFromAssignments(), ProgramMemoryState::removeModifiedVars(), and valueFlowForLoopSimplify().
bool conditionIsTrue | ( | const Token * | condition, |
ProgramMemory | pm, | ||
const Settings & | settings | ||
) |
Is condition always true when variable has given value?
condition | top ast token in condition |
pm | program memory |
Definition at line 216 of file programmemory.cpp.
References evaluateCondition().
Referenced by evalSameCondition(), ValueFlowAnalyzer::evaluateInt(), fillProgramMemoryFromAssignments(), ProgramMemoryState::removeModifiedVars(), and valueFlowForLoopSimplify().
|
static |
Definition at line 648 of file programmemory.cpp.
References ValueFlow::combineValueProperties(), Token::eString, ValueFlow::Value::FLOAT, ValueFlow::Value::floatValue, getStringLiteral(), Token::getStrLength(), ValueFlow::Value::INT, ValueFlow::Value::intvalue, ValueFlow::Value::isFloatValue(), ValueFlow::Value::isIntValue(), ValueFlow::Value::isTokValue(), Token::str(), Token::tokType(), ValueFlow::Value::tokvalue, ValueFlow::Value::unknown(), and ValueFlow::Value::valueType.
Referenced by getBuiltinLibraryFunction().
|
static |
Definition at line 1224 of file programmemory.cpp.
References conditionIsTrue(), and programMemoryParseCondition().
|
static |
Definition at line 579 of file programmemory.cpp.
References asFloat(), ValueFlow::Value::bound, calculate(), ValueFlow::combineValueProperties(), contains(), error, ValueFlow::Value::FLOAT, ValueFlow::Value::floatValue, ValueFlow::Value::INT, ValueFlow::Value::intvalue, isFalse(), ValueFlow::Value::isFloatValue(), ValueFlow::Value::isImpossible(), isIntegralValue(), ValueFlow::Value::isIntValue(), ValueFlow::Value::isIteratorValue(), isNumericValue(), ValueFlow::Value::isSymbolicValue(), isTrue(), ValueFlow::Value::Point, ValueFlow::Value::setImpossible(), ValueFlow::Value::setPossible(), ValueFlow::Value::tokvalue, ValueFlow::Value::unknown(), and ValueFlow::Value::valueType.
Referenced by findExpressionChangedSkipDeadCode(), findTokenSkipDeadCode(), findTokensSkipDeadCode(), findTokensSkipDeadCodeImpl(), parseCompareEachInt(), ValueFlow::parseCompareInt(), and Variable::Variable().
|
static |
Definition at line 201 of file programmemory.cpp.
References error, and execute().
Referenced by conditionIsFalse(), and conditionIsTrue().
ValueFlow::Value evaluateLibraryFunction | ( | const std::unordered_map< nonneg int, ValueFlow::Value > & | args, |
const std::string & | returnValue, | ||
const Settings & | settings, | ||
bool | cpp | ||
) |
Definition at line 1763 of file programmemory.cpp.
References createTokenFromExpression(), execute(), ProgramMemory::setValue(), and ValueFlow::Value::unknown().
Referenced by valueFlowLibraryFunction().
std::vector<ValueFlow::Value> execute | ( | const Scope * | scope, |
ProgramMemory & | pm, | ||
const Settings & | settings | ||
) |
Definition at line 1757 of file programmemory.cpp.
|
static |
Definition at line 1751 of file programmemory.cpp.
Referenced by ConditionHandler::afterCondition(), evaluateCondition(), ValueFlowAnalyzer::evaluateInt(), evaluateLibraryFunction(), execute(), fillProgramMemoryFromAssignments(), fillProgramMemoryFromConditions(), programMemoryParseCondition(), valueFlowForLoop2(), and valueFlowFunctionReturn().
void execute | ( | const Token * | expr, |
ProgramMemory & | programMemory, | ||
MathLib::bigint * | result, | ||
bool * | error, | ||
const Settings & | settings | ||
) |
Definition at line 1792 of file programmemory.cpp.
References error, execute(), ValueFlow::Value::intvalue, ValueFlow::Value::isImpossible(), and ValueFlow::Value::isIntValue().
|
static |
Definition at line 360 of file programmemory.cpp.
References Token::astOperand1(), Token::astOperand2(), conditionIsFalse(), conditionIsTrue(), execute(), Token::exprId(), getCondTokFromEnd(), ProgramMemory::hasValue(), isBasicForLoop(), isVariableChanged(), Token::Match(), Token::previous(), ProgramMemory::setUnknown(), ProgramMemory::setValue(), Token::simpleMatch(), and ExprIdToken::tok.
Referenced by ProgramMemoryState::addState(), and getProgramMemory().
|
static |
Definition at line 335 of file programmemory.cpp.
References Scope::bodyEnd, Scope::eElse, Scope::eFor, Scope::eIf, error, Scope::eWhile, execute(), getCondTokFromEnd(), Scope::isLocal(), Scope::nestedIn, programMemoryParseCondition(), and Scope::type.
Referenced by ProgramMemoryState::addState(), fillProgramMemoryFromConditions(), and getProgramMemory().
|
static |
Definition at line 355 of file programmemory.cpp.
References fillProgramMemoryFromConditions(), Token::scope(), and ExprIdToken::tok.
|
static |
Definition at line 221 of file programmemory.cpp.
Referenced by programMemoryParseCondition().
|
static |
Definition at line 1202 of file programmemory.cpp.
References createBuiltinLibraryFunctions().
|
static |
Definition at line 427 of file programmemory.cpp.
Referenced by getProgramMemory().
ProgramMemory getProgramMemory | ( | const Token * | tok, |
const Token * | expr, | ||
const ValueFlow::Value & | value, | ||
const Settings & | settings | ||
) |
Get program memory by looking backwards from given token.
Definition at line 539 of file programmemory.cpp.
References ValueFlow::Value::condition, fillProgramMemoryFromAssignments(), fillProgramMemoryFromConditions(), getInitialProgramState(), ProgramMemory::replace(), ProgramMemory::setValue(), and ValueFlow::Value::tokvalue.
Referenced by ValueFlowAnalyzer::evaluateInt(), and valueFlowForLoopSimplify().
|
static |
Definition at line 256 of file programmemory.cpp.
References Token::astOperand2(), Token::link(), Token::linkAt(), Token::previous(), Token::simpleMatch(), and ExprIdToken::tok.
Referenced by fillProgramMemoryFromAssignments().
|
static |
Definition at line 239 of file programmemory.cpp.
References ValueFlow::Value::intvalue, ValueFlow::Value::isImpossible(), and ValueFlow::Value::isUninitValue().
Referenced by evaluate(), isTrueOrFalse(), and TemplateSimplifier::simplifyTemplates().
|
static |
Definition at line 574 of file programmemory.cpp.
References ValueFlow::Value::isIntValue(), ValueFlow::Value::isIteratorValue(), and ValueFlow::Value::isSymbolicValue().
Referenced by evaluate().
|
static |
Definition at line 551 of file programmemory.cpp.
References ValueFlow::Value::isFloatValue(), and ValueFlow::Value::isIntValue().
Referenced by evaluate().
|
static |
Definition at line 230 of file programmemory.cpp.
References ValueFlow::Value::intvalue, ValueFlow::Value::isImpossible(), and ValueFlow::Value::isUninitValue().
Referenced by CheckCondition::checkBadBitmaskCheck(), evaluate(), and isTrueOrFalse().
|
static |
Definition at line 248 of file programmemory.cpp.
|
static |
Definition at line 274 of file programmemory.cpp.
References ValueFlow::asImpossible(), Token::astOperand1(), Token::astOperand2(), Library::Container::EMPTY, error, execute(), Token::exprId(), findExpressionChanged(), frontIs(), Library::getContainerFromYield(), ValueFlow::Value::intvalue, ValueFlow::Value::isIntValue(), Settings::library, Token::Match(), Token::next(), ValueFlow::parseCompareInt(), ProgramMemory::setContainerSizeValue(), ProgramMemory::setIntValue(), ProgramMemory::setValue(), Token::simpleMatch(), Library::Container::SIZE, Token::str(), and ExprIdToken::tok.
Referenced by ProgramMemoryState::assume(), evalSameCondition(), and fillProgramMemoryFromConditions().
|
static |
Definition at line 1237 of file programmemory.cpp.
|
static |
Definition at line 560 of file programmemory.cpp.
|
static |
Definition at line 420 of file programmemory.cpp.
References ProgramMemory::erase_if(), ExprIdToken::getExpressionId(), isVariableChanged(), and ExprIdToken::tok.
|
static |
Definition at line 1217 of file programmemory.cpp.
References TokenExprIdCompare().
Definition at line 1210 of file programmemory.cpp.
References Token::exprId().
Referenced by setDifference().
Definition at line 1213 of file programmemory.cpp.
References Token::exprId().