-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_maker.h
206 lines (191 loc) · 4.61 KB
/
state_maker.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/******************************************************************************
* File: state_maker.h
* Description: class for getting all states of C program.
* Date: March 2013
* Author: Valery Bitsoev
* Email: valner47@gmail.com
*******************************************************************************/
#ifndef STATE_MAKER_H
#define STATE_MAKER_H
#include <fstream>
#include <iostream>
#include <utility>
#include <set>
/**
* @brief structure to store vars of functions
*/
class IntVariable
{
public:
/**
* @brief default constructor
*/
IntVariable():m_value(0),m_init_flag(false){}
/**
* @brief Assigment operator <IntVar> = <IntVar>
* @param right right part of assigment operator
* @return self object
*/
IntVariable& operator=(const IntVariable & right)
{
this->m_value = right.m_value;
this->m_init_flag = right.m_init_flag;
return *this;
}
/**
* @brief Assigment operator <IntVar> = <Int>
* @param right right part of assigment operator
* @return self object
*/
IntVariable& operator=(int right)
{
this->m_value = right;
this->m_init_flag = true;
return *this;
}
/**
* @brief overloaded output operator for IntVariable
* @param stream output stream
* @param right object to printing
* @return Reference to stream
*/
friend std::ostream& operator<<(std::ostream& stream, const IntVariable& right);
/**
* @brief operator less
* @param right - right part of operator
*/
const bool operator<(const IntVariable& right) const
{
if(m_init_flag == right.m_init_flag)
return m_value < right.m_value;
return false;
}
private:
/**
* @brief stored value
*/
int m_value;
/**
* @brief indicates initialization of variable
*/
bool m_init_flag;
};
struct FuncVars
{
IntVariable a;
IntVariable b;
IntVariable x;
IntVariable y;
unsigned int counter;
};
/**
* @brief class to differ states in set
*/
class StateDiff
{
public:
/**
* @brief class constructor
* @param fCounter - counter of f
* @param gCounter - counter of g
* @param h - value of global variable
*/
StateDiff(unsigned int fCounter, unsigned int gCounter, IntVariable h):m_fCounter(fCounter),m_gCounter(gCounter),m_h(h){}
/**
* @brief operator less
* @param right - right part of operator
* @return true if left < right, false otherwise
*/
const bool operator< (const StateDiff& right) const
{
if (m_fCounter < right.m_fCounter) return true;
if (m_fCounter > right.m_fCounter) return false;
if (m_gCounter < right.m_gCounter) return true;
if (m_gCounter > right.m_gCounter) return false;
return m_h < right.m_h;
}
private:
/**
* @brief counter of function f
*/
unsigned int m_fCounter;
/**
* @brief counter of function g
*/
unsigned int m_gCounter;
/**
* @brief global variable
*/
IntVariable m_h;
};
/**
* @brief class for getting all states of C program.
*/
class StateMaker
{
public:
/**
* @brief class constructor
* @param filename - name of output file
* @param count flag - flag, indicates if need print states number
*/
StateMaker(char* filename, bool count_flag);
/**
* @brief class destructor
*/
~StateMaker();
/**
* @brief generate and print states in console or file
* @param f_a initial value of f::a
* @param f_b initial value of f::b
* @param g_a initial value of g::a
* @param g_b initial value of g::b
*/
void PrintStates(int f_a, int f_b, int g_a, int g_b);
private:
/**
* @brief number of generated states
*/
unsigned int m_states_number;
/**
* @brief flag, indicates if need print states number
*/
unsigned int m_count_flag;
/**
* @brief flag, indicates if output should be to file
*/
bool m_to_file_flag;
/**
* @brief stream for output file
*/
std::ofstream m_file;
/**
* @brief stores pairs of counters, already generated by program
*/
std::set<StateDiff> m_old;
/**
* @brief generates and prints all states after state, described by f, g and h
* @param f - state of function f
* @param g - state of function g
* @param h - value of global variable
*/
void GenerateStates(FuncVars f, FuncVars g, IntVariable h);
/**
* @brief do step by f code
* @param f - state of function f
* @param g - state of function g
* @param h - state of global variable
*/
void StepInF(FuncVars f, FuncVars g, IntVariable h);
/**
* @brief do step by g code
* @param f - state of function f
* @param g - state of function g
* @param h - state of global variable
*/
void StepInG(FuncVars f, FuncVars g, IntVariable h);
// Copy isn't allowed
StateMaker(StateMaker&);
StateMaker& operator=(StateMaker&);
};
#endif //STATE_MAKER_H