-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathType.cpp
51 lines (38 loc) · 1019 Bytes
/
Type.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
#include "Type.h"
#include <iostream>
#include <vector>
#include <fstream>
/*
Define constructors for types
*/
using namespace std;
void Structure::Collect(std::string field, Type *type) {
elementTypes.push_back(new NameTypePair(field, type));
}
Type* Structure::getElementType(std::string field) {
for(std::vector<NameTypePair*>::iterator itor = elementTypes.begin(); itor != elementTypes.end(); ++itor) {
//os << (*itor)->name << endl;
if(field == (*itor)->name) {
return (*itor)->type;
}
}
return new EmptyType();
}
void Int::Emit(ofstream& os) {
os << "i32";
}
void Structure::Emit(ofstream& os) {
os << "%struct." << typeName;
}
void Array::Emit(ofstream& os) {
os << "[" << length << " x ";
elementType->Emit(os);
os << "]";
}
void Bool::Emit(ofstream& os) {
os << "i1";
}
void MetaType::Emit(ofstream& os) {}
void TupleType::Emit(ofstream& os) {}
void FuncType::Emit(ofstream& os) {}
void EmptyType::Emit(ofstream& os) {}