-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeClass.h
257 lines (224 loc) · 5.3 KB
/
TypeClass.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
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
#include <vector>
#include <string>
#ifndef TYPECLASS
#define TYPECLASS
class Type;
class ListType; // helper type
class TypeFun;
class TypeRecord;
class TypeArray;
class TypeInteger;
class TypeReal;
class TypeBool;
class TypeChar;
class ReturnType;
class Type
{
std::string name_ = "type";
public:
virtual std::string getName() = 0;
virtual Type *clone() const = 0;
int line_number, char_number;
void swap(Type &);
virtual std::string toString() = 0;
};
class ReturnType : public Type
{
std::string name_ = "return_type";
public:
Type *type_;
std::string getName()
{
return this->name_;
}
std::string toString()
{
std::string returnString = "[" + this->name_ + " ";
if (type_ == nullptr)
returnString += this->type_->toString() + "]";
else
returnString += "]";
return returnString;
}
ReturnType(const ReturnType &);
ReturnType &operator=(const ReturnType &);
ReturnType(Type *p1);
~ReturnType();
void swap(ReturnType &);
virtual ReturnType *clone() const;
};
class ListType : public Type
{
std::string name_ = "list";
public:
std::vector<Type *> types_;
std::string getName()
{
return this->name_;
}
std::string toString()
{
std::string returnString = "[" + this->name_ + " (";
for (int i = 0; i < this->types_.size(); ++i)
{
returnString += (this->types_[i]->toString() + " ");
}
returnString += ")]";
return returnString;
}
ListType(const ListType &);
ListType &operator=(const ListType &);
ListType(std::vector<Type *> p1);
~ListType();
void swap(ListType &);
virtual ListType *clone() const { return nullptr; };
};
class TypeFun : public Type
{
std::string name_ = "fun";
public:
ListType *listtype_;
Type *type_;
std::string getName()
{
return this->name_;
}
std::string toString()
{
std::string returnString = "[" + this->name_ + " (";
for (int i = 0; i < this->listtype_->types_.size(); ++i)
{
returnString += (this->listtype_->types_[i]->toString() + " ");
}
if (this->type_ != nullptr)
returnString += (") -> " + this->type_->toString() + "]");
else
returnString += (")]");
return returnString;
}
TypeFun(const TypeFun &);
TypeFun &operator=(const TypeFun &);
TypeFun(ListType *p1, Type *p2);
~TypeFun();
void swap(TypeFun &);
virtual TypeFun *clone() const;
};
class TypeRecord : public Type
{
std::string name_ = "record";
public:
ListType *listtype_;
std::vector<std::string> names;
std::string toString()
{
std::string returnString = "[" + this->name_ + " (";
for (int i = 0; i < this->listtype_->types_.size(); ++i)
{
returnString += names[i] + " : ";
returnString += (this->listtype_->types_[i]->toString() + " ");
}
returnString += ")]";
return returnString;
}
std::string getName()
{
return this->name_;
}
TypeRecord(const TypeRecord &);
TypeRecord &operator=(const TypeRecord &);
TypeRecord(ListType *p1, std::vector<std::string> p2);
~TypeRecord();
void swap(TypeRecord &);
virtual TypeRecord *clone() const;
};
class TypeArray : public Type
{
std::string name_ = "array";
public:
Type *type_;
std::string toString()
{
std::string returnString = "[" + this->name_ +
" " + this->type_->toString() + "]";
return returnString;
}
std::string getName()
{
return this->name_;
}
TypeArray(const TypeArray &);
TypeArray &operator=(const TypeArray &);
TypeArray(Type *p1);
~TypeArray();
void swap(TypeArray &);
virtual TypeArray *clone() const;
};
class TypeInteger : public Type
{
std::string name_ = "integer";
public:
std::string toString()
{
std::string returnString = "[" + this->name_ + "]";
return returnString;
}
std::string getName()
{
return this->name_;
}
TypeInteger(){};
void swap(Type &){};
virtual TypeInteger *clone() const;
};
class TypeReal : public Type
{
std::string name_ = "real";
public:
std::string toString()
{
std::string returnString = "[" + this->name_ + "]";
return returnString;
}
std::string getName()
{
return this->name_;
}
TypeReal(){};
void swap(Type &){};
virtual TypeReal *clone() const;
};
class TypeBool : public Type
{
std::string name_ = "bool";
public:
std::string toString()
{
std::string returnString = "[" + this->name_ + "]";
return returnString;
}
std::string getName()
{
return this->name_;
}
void swap(Type &){};
TypeBool(){};
virtual TypeBool *clone() const { return nullptr; };
};
class TypeChar : public Type
{
std::string name_ = "char";
public:
std::string toString()
{
std::string returnString = "[" + this->name_ + "]";
return returnString;
}
TypeChar(){};
std::string getName()
{
return this->name_;
}
void swap(Type &){};
virtual TypeChar *clone() const { return nullptr; };
};
#endif