-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.cpp
More file actions
84 lines (76 loc) · 2.02 KB
/
Copy pathType.cpp
File metadata and controls
84 lines (76 loc) · 2.02 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
#include "Type.h"
#include <assert.h>
#include <sstream>
IntType TypeSystem::commonConstInt = IntType(INTSIZE, true);
IntType TypeSystem::commonInt = IntType(INTSIZE);
IntType TypeSystem::commonBool = IntType(1);
VoidType TypeSystem::commonVoid = VoidType();
Type* TypeSystem::constIntType = &commonConstInt;
Type* TypeSystem::intType = &commonInt;
Type* TypeSystem::voidType = &commonVoid;
Type* TypeSystem::boolType = &commonBool;
std::string IntType::toStr()
{
std::ostringstream buffer;
if (constant)
buffer << "i";
else
buffer << "i";
buffer << size;
return buffer.str();
}
std::string VoidType::toStr()
{
return "void";
}
std::string ArrayType::toStr()
{
std::vector<std::string> vec;
Type* temp = this;
int count = 0;
bool flag = false;
while (temp && temp->isArray())
{
std::ostringstream buffer;
if (((ArrayType*)temp)->getCurDimWidth() == -1)
flag = true;
else
{
buffer << "[" << ((ArrayType*)temp)->getCurDimWidth() << " x ";
count++;
vec.push_back(buffer.str());
}
temp = ((ArrayType*)temp)->getElementType();
}
assert(temp->isInt());
std::ostringstream buffer;
for (auto it = vec.begin(); it != vec.end(); it++)
buffer << *it;
buffer << "i32";
while (count--)
buffer << ']';
if (flag)
buffer << '*';
return buffer.str();
}
std::string FunctionType::toStr() {
std::ostringstream buffer;
buffer << returnType->toStr() << "(";
for (auto it = paramsType.begin(); it != paramsType.end(); it++) {
buffer << (*it)->toStr();
if (it + 1 != paramsType.end())
buffer << ", ";
}
buffer << ')';
return buffer.str();
}
std::string StringType::toStr() {
std::ostringstream buffer;
buffer << "const char[" << length << "]";
return buffer.str();
}
std::string PointerType::toStr() {
std::ostringstream buffer;
buffer << valueType->toStr() << "*";
return buffer.str();
}