forked from danmar/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammemory.h
More file actions
89 lines (59 loc) · 2.54 KB
/
programmemory.h
File metadata and controls
89 lines (59 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef GUARD_PROGRAMMEMORY_H
#define GUARD_PROGRAMMEMORY_H
#include "utils.h"
#include "valueflow.h" // needed for alias
#include "mathlib.h"
#include <map>
#include <unordered_map>
class Token;
struct ProgramMemory {
using Map = std::unordered_map<nonneg int, ValueFlow::Value>;
Map values;
void setValue(nonneg int exprid, const ValueFlow::Value& value);
const ValueFlow::Value* getValue(nonneg int exprid, bool impossible = false) const;
bool getIntValue(nonneg int exprid, MathLib::bigint* result) const;
void setIntValue(nonneg int exprid, MathLib::bigint value);
bool getContainerSizeValue(nonneg int exprid, MathLib::bigint* result) const;
bool getContainerEmptyValue(nonneg int exprid, MathLib::bigint* result) const;
void setUnknown(nonneg int exprid);
bool getTokValue(nonneg int exprid, const Token** result) const;
bool hasValue(nonneg int exprid);
void swap(ProgramMemory &pm);
void clear();
bool empty() const;
void replace(const ProgramMemory &pm);
void insert(const ProgramMemory &pm);
};
void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Token* endTok, const Settings* settings, bool then);
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;
};
void execute(const Token *expr,
ProgramMemory * const programMemory,
MathLib::bigint *result,
bool *error);
/**
* 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 exprid, const ValueFlow::Value& value);
ProgramMemory getProgramMemory(const Token *tok, const ProgramMemory::Map& vars);
#endif