-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.h
117 lines (102 loc) · 2.25 KB
/
type.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
#pragma once
#include <string>
#include <vector>
#include <map>
#include <list>
//#include "utility.h"
#include <memory>
using namespace std;
class TypeAST{
public:
virtual ~TypeAST(){}
virtual string GetName()=0;
};
//単一の型
class BasicTypeAST : public TypeAST{
public:
BasicTypeAST(string n):Name(n){}
string Name;
virtual string GetName(){
return Name;
}
};
//関数型
class FunctionTypeAST : public TypeAST{
public:
FunctionTypeAST(vector<shared_ptr<TypeAST> > t_list):TypeList(t_list){}
vector<shared_ptr<TypeAST> > TypeList;
virtual string GetName(){
string s="fun(";
for(int i=0;i<TypeList.size()-1;i++){
s+=TypeList[i]->GetName();
if(i!=TypeList.size()-2){
s+=",";
}
}
s+=")=>"+TypeList[TypeList.size()-1]->GetName();
return s;
}
};
//継続型
class ContinuationTypeAST : public TypeAST{
public:
ContinuationTypeAST(shared_ptr<TypeAST> t):Type(t){}
shared_ptr<TypeAST> Type;
virtual string GetName(){
string s="continuation(";
s+=Type->GetName();
s+=")";
return s;
}
};
//チャンネル型
class ChannelTypeAST : public TypeAST{
public:
ChannelTypeAST(shared_ptr<TypeAST> t):Type(t){}
shared_ptr<TypeAST> Type;
virtual string GetName(){
string s="channel(";
s+=Type->GetName();
s+=")";
return s;
}
};
//リスト型
class ListTypeAST : public TypeAST{
public:
ListTypeAST(shared_ptr<TypeAST> t):ContainType(t){}
shared_ptr<TypeAST> ContainType;
virtual string GetName(){
if (ContainType == nullptr){
return "[]";
}
return "["+ContainType->GetName()+"]";
}
};
//配列型
class VectorTypeAST : public TypeAST{
public:
VectorTypeAST(shared_ptr<TypeAST> t):ContainType(t){}
shared_ptr<TypeAST> ContainType;
virtual string GetName(){
return "vector("+ContainType->GetName()+")";
}
};
//タプル型
class TupleTypeAST : public TypeAST{
public:
TupleTypeAST(vector<shared_ptr<TypeAST> > t_list):ContainTypeList(t_list){}
vector<shared_ptr<TypeAST> > ContainTypeList;
virtual string GetName(){
string name="(";
for(int i=0;i<ContainTypeList.size();i++){
name+=ContainTypeList[i]->GetName();
if(i!=ContainTypeList.size()-1){
name+=",";
}
}
name+=")";
return name;
}
};
string Var2Str(pair<string, shared_ptr<TypeAST>> var);