/
CLIPSObjectBuilder.cpp
160 lines (160 loc) · 4.67 KB
/
CLIPSObjectBuilder.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
#include "ConstructionTools.h"
using namespace llvm;
char openParen[2] = "(";
char closeParen[2] = ")";
char space[2] = " ";
CLIPSObjectBuilder::CLIPSObjectBuilder(std::string n, std::string t, FunctionNamer& uidCreator) {
converted = false;
opened = false;
closed = false;
name = n;
type = t;
stream = new raw_string_ostream(tmp);
namer = &uidCreator;
}
CLIPSObjectBuilder::~CLIPSObjectBuilder() {
delete stream;
}
void CLIPSObjectBuilder::setParent(char* p) { addField("Parent", p); }
void CLIPSObjectBuilder::setParent(const char* p) { addField("Parent", p); }
void CLIPSObjectBuilder::setPointer(PointerAddress v) { addField("Pointer", v); }
void CLIPSObjectBuilder::addField(const char* n, unsigned v) {
if(v != 0) {
(*stream) << openParen << n << space << v << closeParen;
}
}
void CLIPSObjectBuilder::addField(const char* n, PointerAddress v) {
if(v != 0) {
(*stream) << openParen << n << space << v << closeParen;
}
}
void CLIPSObjectBuilder::addField(const char* n, float v) {
(*stream) << openParen << n << space << v << closeParen;
}
void CLIPSObjectBuilder::addField(const char* n, double v) {
(*stream) << openParen << n << space << v << closeParen;
}
void CLIPSObjectBuilder::addField(const char* n, char* v) {
(*stream) << openParen << n << space << v << closeParen;
}
void CLIPSObjectBuilder::addField(const char* n, const char* v) {
(*stream) << openParen << n << space << v << closeParen;
}
void CLIPSObjectBuilder::addField(const char* n, std::string v) {
if(v.length() > 0) (*stream) << openParen << n << space << v << closeParen;
}
void CLIPSObjectBuilder::addField(const char* n, bool v) {
(*stream) << openParen << n;
if(v) {
(*stream) << " TRUE)";
} else {
(*stream) << " FALSE)";
}
}
void CLIPSObjectBuilder::addField(const char* n, int v) {
if(v != 0) {
(*stream) << openParen << n << space << v << closeParen;
}
}
void CLIPSObjectBuilder::addField(const char* n, uint64_t v) {
if(v != 0) {
(*stream) << openParen << n << space << v << closeParen;
}
}
void CLIPSObjectBuilder::addField(const char* n, int64_t v) {
if(v != 0) {
(*stream) << openParen << n << space << v << closeParen;
}
}
void CLIPSObjectBuilder::addField(const char* n, llvm::StringRef ref) {
(*stream) << openParen << n << space << ref << closeParen;
}
void CLIPSObjectBuilder::open() {
if(!opened) {
(*stream) << "(" << name << " of " << type << " ";
opened = true;
}
}
void CLIPSObjectBuilder::close() {
if(!closed) {
(*stream) << closeParen; //close it
closed = true;
}
}
void CLIPSObjectBuilder::convertToKnowledge(void* theEnv) {
if(closed && !converted) {
EnvMakeInstance(theEnv, (char*)stream->str().c_str());
converted = true;
}
}
void CLIPSObjectBuilder::addFields(PointerAddress pointer, KnowledgeConstruction *kc, char* parent) {
setParent(parent);
setPointer(pointer);
std::string& name = getName();
namer->tryRegisterPointerToName(pointer, name);
}
void CLIPSObjectBuilder::addTrueField(const char* n) {
(*stream) << openParen << n << " TRUE)";
}
void CLIPSObjectBuilder::addFalseField(const char* n) {
(*stream) << openParen << n << " FALSE)";
}
void CLIPSObjectBuilder::openField(const char* name) {
(*stream) << openParen << name;
}
void CLIPSObjectBuilder::appendValue(unsigned v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(PointerAddress v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(int v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(float v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(double v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(char* v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(const char* v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(std::string v) {
if(!v.empty()) {
(*stream) << space << v;
}
}
void CLIPSObjectBuilder::appendValue(llvm::StringRef v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(bool v) {
if(v) {
appendTrue();
} else {
appendFalse();
}
}
void CLIPSObjectBuilder::appendValue(uint64_t v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendValue(int64_t v) {
(*stream) << space << v;
}
void CLIPSObjectBuilder::appendTrue() {
(*stream) << " TRUE";
}
void CLIPSObjectBuilder::appendFalse() {
(*stream) << " FALSE";
}
void CLIPSObjectBuilder::closeField() {
(*stream) << closeParen;
}
void CLIPSObjectBuilder::addStringField(const char* n, const std::string& string) {
if(string.size() > 0) {
(*stream) << "(" << n << " \"" << string << "\")";
}
}