-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsttr.cpp
279 lines (276 loc) · 8.14 KB
/
sttr.cpp
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// sttr_visitor.cpp
//
#include "sttr_visitor.h"
#define LZZ_INLINE inline
namespace sttr {
void * Visitor_Base::getSignature () {
// Must be present in derived classes
return getSignatureStatic();
}
}
namespace sttr {
void * Visitor_Base::getSignatureStatic () {
// Must be present in derived classes
return (void*) sttr::getTypeSignature<Visitor_Base>();
}
}
#undef LZZ_INLINE
// sttr.cpp
//
#include "sttr.h"
#define LZZ_INLINE inline
namespace sttr {
RegBase::RegBase (char const * _name)
: name (_name), isStatic (false), isConst (false), isVariable (false), isFunction (false), nullValueSet (false), nullValueValue (0.0), mNamespace (NULL), userFlags (0), userString (""), userData (NULL) {}
}
namespace sttr {
RegBase::~ RegBase () {}
}
namespace sttr {
void * RegBase::construct () { return (void *) 0; }
}
namespace sttr {
void RegBase::visit (Visitor_Base * V) {}
}
namespace sttr {
void RegBase::visitClass (Visitor_Base * V) {}
}
namespace sttr {
std::string RegBase::getTypeName () { return ""; }
}
namespace sttr {
std::string RegBase::getTypePointingTo () { return ""; }
}
namespace sttr {
unsigned long long int const RegBase::getOffset () const { return 0; }
}
namespace sttr {
RegNamespace::RegNamespace (char const * _name)
: parent (NULL), name (_name), thisClass (NULL), thisClassSig (NULL), uninstantiatedParent (NULL) {}
}
namespace sttr {
RegNamespace::~ RegNamespace () {
clear();
}
}
namespace sttr {
void RegNamespace::clear () {
for (RegBase * RB : members) delete RB;
for (RegNamespace * RN : classes) delete RN;
if (thisClass) delete thisClass;
thisClass = NULL;
// if (baseClassTuple) delete baseClassTuple;
members.clear();
classes.clear();
}
}
namespace sttr {
RegNamespace & RegNamespace::setUserFlags (uint32_t const & userFlags) {
// Sets the userFlags for the last inserted member
assert (members.size() && "Trying to sttr::RegNamespace::setUserFlags without registering a field");
RegBase * R = members[members.size()-1];
R->userFlags = userFlags;
return *this;
}
}
namespace sttr {
RegNamespace & RegNamespace::setUserString (std::string const & userString) {
// Sets the userString for the last inserted member
assert (members.size() && "Trying to sttr::RegNamespace::setUserString without registering a field");
RegBase * R = members[members.size()-1];
R->userString = userString;
return *this;
}
}
namespace sttr {
RegNamespace & RegNamespace::setUserData (void * userData) {
// Sets the userString for the last inserted member
assert (members.size() && "Trying to sttr::RegNamespace::setUserData without registering a field");
RegBase * R = members[members.size()-1];
R->userData = userData;
return *this;
}
}
namespace sttr {
RegNamespace & RegNamespace::setClassUserFlags (uint32_t const & userFlags) {
// Sets the userFlags for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::setClassUserFlags with a namespace that is not a class");
thisClass->userFlags = userFlags;
return *this;
}
}
namespace sttr {
RegNamespace & RegNamespace::setClassUserString (std::string const & userString) {
// Sets the userString for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::setClassUserString with a namespace that is not a class");
thisClass->userString = userString;
return *this;
}
}
namespace sttr {
RegNamespace & RegNamespace::setClassUserData (void * userData) {
// Sets the userString for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::setClassUserData with a namespace that is not a class");
thisClass->userData = userData;
return *this;
}
}
namespace sttr {
uint32_t RegNamespace::getClassUserFlags () const {
// Sets the userFlags for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::getClassUserFlags with a namespace that is not a class");
return thisClass->userFlags;
}
}
namespace sttr {
std::string RegNamespace::setClassUserString () const {
// Sets the userString for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::getClassUserString with a namespace that is not a class");
return thisClass->userString;
}
}
namespace sttr {
void * RegNamespace::getClassUserData () const {
// Sets the userString for the last inserted member
assert (thisClass && "Trying to sttr::RegNamespace::getClassUserData with a namespace that is not a class");
return thisClass->userData;
}
}
namespace sttr {
RegNamespace & RegNamespace::endClass () {
if (parent) return *parent;
return *this;
}
}
namespace sttr {
void * RegNamespace::construct_retVoidPtr () {
if (thisClass)
return thisClass->construct();
return NULL;
}
}
namespace sttr {
RegNamespace & RegNamespace::findClass (char const * class_name) {
RegNamespace * R = findClassPointer(class_name);
assert(R && "sttr::RegNamespace::findClass : class not found");
return *R;
}
}
namespace sttr {
RegNamespace * RegNamespace::findClassPointer (char const * class_name) {
for (RegNamespace * R : classes) {
if (R->thisClass) {
//std::cout << "comp a: " << name << "->" << R->thisClass->name << " " << class_name << std::endl;
if (!strcmp(R->thisClass->name, class_name))
return R;
}
}
for (RegNamespace * R : classes) {
RegNamespace * R2 = R->findClassPointer(class_name);
if (R2)
return R2;
}
return NULL;
}
}
namespace sttr {
RegNamespace * RegNamespace::findClassPointerBySig (void * target) {
if (target == thisClassSig) return this;
for (RegNamespace * R : classes) {
if (R->thisClass) {
//std::cout << "comp b: " << name << "->" << R->name << " " << R->thisClassSig << " " << target<< std::endl;
if (R->thisClassSig == target)
return R;
}
}
for (RegNamespace * R : classes) {
RegNamespace * R2 = R->findClassPointerBySig(target);
if (R2)
return R2;
}
return NULL;
}
}
namespace sttr {
RegNamespace * RegNamespace::getBaseClass () {
// Returns the base class of this class
if (thisClass && parent) {
if (parent->thisClass)
return parent->getBaseClass();
}
return this;
}
}
namespace sttr {
bool RegNamespace::isDerivedFromSig (void * target) {
// Returns true if this type is a instance of or derived from target
if (thisClassSig == target) return true;
if (parent) return parent->isDerivedFromSig(target);
return false;
}
}
namespace sttr {
void RegNamespace::visitRecursive (Visitor_Base * v) {
// Recusively visits all classes and members. Goes down the tree
for (RegNamespace * R : classes) {
R->visitRecursive(v);
}
visit(v);
}
}
namespace sttr {
void RegNamespace::visitPolymorthic (Visitor_Base * v) {
// Recusively visits all classes and members, goes up the class tree
// Classes are visited in order Base->Derived1->Derived2->...->This
RegNamespace * R = this;
if (!R) return;
std::vector<RegNamespace*> chain;
while (R->thisClass) {
chain.push_back(R);
R = R->parent;
if (!R) break;
}
for (unsigned int i = chain.size()-1; i < chain.size(); --i) {
chain[i]->visit(v);
}
}
}
namespace sttr {
void RegNamespace::visit (Visitor_Base * v) {
// Visits this class. Does not account for polymorthisim
if (thisClass) thisClass->visitClass(v);
// if (baseClassTuple) baseClassTuple->visitBaseClassTuple(v);
for (RegBase * RB : members)
RB->visit(v);
}
}
namespace sttr {
std::string RegNamespace::toString (int const indent) const {
std::string r = "";
for (RegBase * RB : members) {
r += std::string(indent,'\t') + "\tField: "+ RB->name + "\tTypedef: " + RB->getTypeName() + ", Pointing To: " + RB->getTypePointingTo()+ ", isStatic: " + STTR_BTOS(RB->isStatic) + " , isConst: " + STTR_BTOS(RB->isConst) + ", isFunction: " + STTR_BTOS(RB->isFunction) + ", isVariable: " + STTR_BTOS(RB->isVariable) + "\n";
}
for (RegNamespace * RS : classes) {
r += std::string(indent,'\t') + "class " + RS->name + ":\n";
r += RS->toString(indent+1);
}
return r;
}
}
namespace sttr {
std::string RegNamespace::toClassTreeString (int const indent) const {
std::string r = "";
for (RegNamespace * RS : classes) {
r += std::string(indent,'\t') + RS->name + "\n";
r += RS->toClassTreeString(indent+1);
}
return r;
}
}
namespace sttr {
RegNamespace * getGlobalNamespace () {
static RegNamespace R("global");
return &R;
}
}
#undef LZZ_INLINE