2019-10-30 17:57:46 +01:00
|
|
|
#ifndef GUARD_PROGRAMMEMORY_H
|
|
|
|
#define GUARD_PROGRAMMEMORY_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "valueflow.h"
|
|
|
|
#include "mathlib.h"
|
|
|
|
#include <map>
|
2020-02-16 16:02:22 +01:00
|
|
|
#include <unordered_map>
|
2019-10-30 17:57:46 +01:00
|
|
|
|
|
|
|
struct ProgramMemory {
|
2020-02-19 07:55:04 +01:00
|
|
|
using Map = std::unordered_map<nonneg int, ValueFlow::Value>;
|
|
|
|
Map values;
|
2019-10-30 17:57:46 +01:00
|
|
|
|
|
|
|
void setValue(nonneg int varid, const ValueFlow::Value &value);
|
|
|
|
|
|
|
|
bool getIntValue(nonneg int varid, MathLib::bigint* result) const;
|
|
|
|
void setIntValue(nonneg int varid, MathLib::bigint value);
|
|
|
|
|
2020-02-13 16:27:06 +01:00
|
|
|
void setUnknown(nonneg int varid);
|
|
|
|
|
2019-10-30 17:57:46 +01:00
|
|
|
bool getTokValue(nonneg int varid, const Token** result) const;
|
|
|
|
bool hasValue(nonneg int varid);
|
|
|
|
|
|
|
|
void swap(ProgramMemory &pm);
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
|
|
|
|
void replace(const ProgramMemory &pm);
|
|
|
|
|
|
|
|
void insert(const ProgramMemory &pm);
|
|
|
|
};
|
|
|
|
|
2020-02-19 07:55:04 +01:00
|
|
|
struct ProgramMemoryState {
|
|
|
|
ProgramMemory state;
|
|
|
|
std::map<nonneg int, const Token*> origins;
|
|
|
|
|
|
|
|
void insert(const ProgramMemory &pm, const Token* origin = nullptr);
|
|
|
|
void replace(const ProgramMemory &pm, const Token* origin = nullptr);
|
|
|
|
|
|
|
|
void addState(const Token* tok, const ProgramMemory::Map& vars);
|
|
|
|
|
|
|
|
void assume(const Token* tok, bool b);
|
|
|
|
|
|
|
|
void removeModifiedVars(const Token* tok);
|
|
|
|
|
|
|
|
ProgramMemory get(const Token *tok, const ProgramMemory::Map& vars) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-10-30 17:57:46 +01:00
|
|
|
void execute(const Token *expr,
|
2019-10-30 17:58:19 +01:00
|
|
|
ProgramMemory * const programMemory,
|
|
|
|
MathLib::bigint *result,
|
|
|
|
bool *error);
|
2019-10-30 17:57:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is condition always false when variable has given value?
|
|
|
|
* \param condition top ast token in condition
|
|
|
|
* \param programMemory program memory
|
|
|
|
*/
|
|
|
|
bool conditionIsFalse(const Token *condition, const ProgramMemory &programMemory);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is condition always true when variable has given value?
|
|
|
|
* \param condition top ast token in condition
|
|
|
|
* \param programMemory program memory
|
|
|
|
*/
|
|
|
|
bool conditionIsTrue(const Token *condition, const ProgramMemory &programMemory);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get program memory by looking backwards from given token.
|
|
|
|
*/
|
|
|
|
ProgramMemory getProgramMemory(const Token *tok, nonneg int varid, const ValueFlow::Value &value);
|
|
|
|
|
2020-02-19 07:55:04 +01:00
|
|
|
ProgramMemory getProgramMemory(const Token *tok, const ProgramMemory::Map& vars);
|
2020-02-16 16:02:22 +01:00
|
|
|
|
2019-10-30 17:57:46 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|