Cppcheck
Typedefs | Functions
programmemory.cpp File Reference
#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, BuiltinLibraryFunctioncreateBuiltinLibraryFunctions ()
 
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::Valueexecute (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)
 

Typedef Documentation

◆ BuiltinLibraryFunction

using BuiltinLibraryFunction = std::function<ValueFlow::Value(const std::vector<ValueFlow::Value>&)>

Definition at line 647 of file programmemory.cpp.

Function Documentation

◆ addVars()

static void addVars ( ProgramMemory pm,
const ProgramMemory::Map vars 
)
static

Definition at line 463 of file programmemory.cpp.

References ProgramMemory::setValue().

Referenced by ProgramMemoryState::addState().

◆ asFloat()

static double asFloat ( const ValueFlow::Value value)
static

◆ conditionIsFalse()

bool conditionIsFalse ( const Token condition,
ProgramMemory  pm,
const Settings settings 
)

Is condition always false when variable has given value?

Parameters
conditiontop ast token in condition
pmprogram memory

Definition at line 211 of file programmemory.cpp.

References evaluateCondition().

Referenced by ValueFlowAnalyzer::evaluateInt(), fillProgramMemoryFromAssignments(), ProgramMemoryState::removeModifiedVars(), and valueFlowForLoopSimplify().

◆ conditionIsTrue()

bool conditionIsTrue ( const Token condition,
ProgramMemory  pm,
const Settings settings 
)

Is condition always true when variable has given value?

Parameters
conditiontop ast token in condition
pmprogram memory

Definition at line 216 of file programmemory.cpp.

References evaluateCondition().

Referenced by evalSameCondition(), ValueFlowAnalyzer::evaluateInt(), fillProgramMemoryFromAssignments(), ProgramMemoryState::removeModifiedVars(), and valueFlowForLoopSimplify().

◆ createBuiltinLibraryFunctions()

static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibraryFunctions ( )
static

◆ evalSameCondition()

static bool evalSameCondition ( const ProgramMemory state,
const Token storedValue,
const Token cond,
const Settings settings 
)
static

Definition at line 1224 of file programmemory.cpp.

References conditionIsTrue(), and programMemoryParseCondition().

◆ evaluate()

static ValueFlow::Value evaluate ( const std::string &  op,
const ValueFlow::Value lhs,
const ValueFlow::Value rhs 
)
static

◆ evaluateCondition()

static bool evaluateCondition ( MathLib::bigint  r,
const Token condition,
ProgramMemory pm,
const Settings settings 
)
static

Definition at line 201 of file programmemory.cpp.

References error, and execute().

Referenced by conditionIsFalse(), and conditionIsTrue().

◆ evaluateLibraryFunction()

ValueFlow::Value evaluateLibraryFunction ( const std::unordered_map< nonneg int, ValueFlow::Value > &  args,
const std::string &  returnValue,
const Settings settings,
bool  cpp 
)

◆ execute() [1/3]

std::vector<ValueFlow::Value> execute ( const Scope scope,
ProgramMemory pm,
const Settings settings 
)

Definition at line 1757 of file programmemory.cpp.

◆ execute() [2/3]

static ValueFlow::Value execute ( const Token expr,
ProgramMemory pm,
const Settings settings 
)
static

◆ execute() [3/3]

void execute ( const Token expr,
ProgramMemory programMemory,
MathLib::bigint result,
bool *  error,
const Settings settings 
)

◆ fillProgramMemoryFromAssignments()

static void fillProgramMemoryFromAssignments ( ProgramMemory pm,
const Token tok,
const Settings settings,
const ProgramMemory state,
const ProgramMemory::Map vars 
)
static

◆ fillProgramMemoryFromConditions() [1/2]

static void fillProgramMemoryFromConditions ( ProgramMemory pm,
const Scope scope,
const Token endTok,
const Settings settings 
)
static

◆ fillProgramMemoryFromConditions() [2/2]

static void fillProgramMemoryFromConditions ( ProgramMemory pm,
const Token tok,
const Settings settings 
)
static

◆ frontIs()

static bool frontIs ( const std::vector< MathLib::bigint > &  v,
bool  i 
)
static

Definition at line 221 of file programmemory.cpp.

Referenced by programMemoryParseCondition().

◆ getBuiltinLibraryFunction()

static BuiltinLibraryFunction getBuiltinLibraryFunction ( const std::string &  name)
static

Definition at line 1202 of file programmemory.cpp.

References createBuiltinLibraryFunctions().

◆ getInitialProgramState()

static ProgramMemory getInitialProgramState ( const Token tok,
const Token origin,
const Settings settings,
const ProgramMemory::Map vars = ProgramMemory::Map {} 
)
static

Definition at line 427 of file programmemory.cpp.

Referenced by getProgramMemory().

◆ getProgramMemory()

ProgramMemory getProgramMemory ( const Token tok,
const Token expr,
const ValueFlow::Value value,
const Settings settings 
)

◆ isBasicForLoop()

static bool isBasicForLoop ( const Token tok)
static

◆ isFalse()

static bool isFalse ( const ValueFlow::Value v)
static

◆ isIntegralValue()

static bool isIntegralValue ( const ValueFlow::Value value)
static

◆ isNumericValue()

static bool isNumericValue ( const ValueFlow::Value value)
static

Definition at line 551 of file programmemory.cpp.

References ValueFlow::Value::isFloatValue(), and ValueFlow::Value::isIntValue().

Referenced by evaluate().

◆ isTrue()

static bool isTrue ( const ValueFlow::Value v)
static

◆ isTrueOrFalse()

static bool isTrueOrFalse ( const ValueFlow::Value v,
bool  b 
)
static

Definition at line 248 of file programmemory.cpp.

References isFalse(), and isTrue().

◆ programMemoryParseCondition()

static void programMemoryParseCondition ( ProgramMemory pm,
const Token tok,
const Token endTok,
const Settings settings,
bool  then 
)
static

◆ pruneConditions()

static void pruneConditions ( std::vector< const Token * > &  conds,
bool  b,
const std::unordered_map< nonneg int, ValueFlow::Value > &  state 
)
static

Definition at line 1237 of file programmemory.cpp.

◆ removeAssign()

static std::string removeAssign ( const std::string &  assign)
static

Definition at line 560 of file programmemory.cpp.

◆ removeModifiedVars()

static void removeModifiedVars ( ProgramMemory pm,
const Token tok,
const Token origin,
const Settings settings 
)
static

◆ setDifference()

static std::vector<const Token*> setDifference ( const std::vector< const Token * > &  v1,
const std::vector< const Token * > &  v2 
)
static

Definition at line 1217 of file programmemory.cpp.

References TokenExprIdCompare().

◆ TokenExprIdCompare()

static bool TokenExprIdCompare ( const Token tok1,
const Token tok2 
)
static

Definition at line 1210 of file programmemory.cpp.

References Token::exprId().

Referenced by setDifference().

◆ TokenExprIdEqual()

static bool TokenExprIdEqual ( const Token tok1,
const Token tok2 
)
static

Definition at line 1213 of file programmemory.cpp.

References Token::exprId().