-
Notifications
You must be signed in to change notification settings - Fork 1
/
element.h
165 lines (125 loc) · 3.5 KB
/
element.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
//
// Created by Kevin Tan on 2021/10/14.
//
#ifndef CODE_ELEMENT_H
#define CODE_ELEMENT_H
#include <iostream>
#include <fstream>
#include <memory>
#include <utility>
#include <vector>
#include <unordered_map>
#include <cassert>
#define cast dynamic_pointer_cast
using std::cout;
using std::cerr;
using std::endl;
using std::ostream;
using std::ifstream;
using std::ofstream;
using std::string;
using std::shared_ptr;
using std::make_shared;
using std::dynamic_pointer_cast;
using std::vector;
using std::unordered_map;
using std::move;
struct Element {
string fullname;
Element() = default;
explicit Element(string &&name) : fullname(move(name)) {}
friend ostream &operator<<(ostream &out, const Element &self) {
out << self.fullname;
return out;
}
virtual ~Element() = default;
};
using ElementP = shared_ptr<Element>;
struct CompUnit : public Element {
explicit CompUnit() : Element("<CompUnit>") {}
};
struct ConstDecl : public Element {
explicit ConstDecl() : Element("<ConstDecl>") {}
};
struct ConstDef : public Element {
explicit ConstDef() : Element("<ConstDef>") {}
};
struct ConstInitVal : public Element {
explicit ConstInitVal() : Element("<ConstInitVal>") {}
};
struct VarDecl : public Element {
explicit VarDecl() : Element("<VarDecl>") {}
};
struct VarDef : public Element {
explicit VarDef() : Element("<VarDef>") {}
};
struct InitVal : public Element {
explicit InitVal() : Element("<InitVal>") {}
};
struct FuncDef : public Element {
explicit FuncDef() : Element("<FuncDef>") {}
};
struct MainFuncDef : public Element {
explicit MainFuncDef() : Element("<MainFuncDef>") {}
};
struct FuncType : public Element {
explicit FuncType() : Element("<FuncType>") {}
};
struct FuncFormalParams : public Element {
explicit FuncFormalParams() : Element("<FuncFParams>") {}
};
struct FuncFormalParam : public Element {
explicit FuncFormalParam() : Element("<FuncFParam>") {}
};
struct Block : public Element {
explicit Block() : Element("<Block>") {}
};
struct Statement : public Element {
explicit Statement() : Element("<Stmt>") {}
};
struct NormalExpr : public Element {
explicit NormalExpr() : Element("<Exp>") {}
};
struct ConditionExpr : public Element {
explicit ConditionExpr() : Element("<Cond>") {}
};
struct LValue : public Element {
explicit LValue() : Element("<LVal>") {}
};
struct PrimaryExpr : public Element {
explicit PrimaryExpr() : Element("<PrimaryExp>") {}
};
struct Number : public Element {
explicit Number() : Element("<Number>") {}
};
struct UnaryExpr : public Element {
explicit UnaryExpr() : Element("<UnaryExp>") {}
};
struct UnaryOp : public Element {
explicit UnaryOp() : Element("<UnaryOp>") {}
};
struct FuncRealParams : public Element {
explicit FuncRealParams() : Element("<FuncRParams>") {}
};
struct MulDivExpr : public Element {
explicit MulDivExpr() : Element("<MulExp>") {}
};
struct AddSubExpr : public Element {
explicit AddSubExpr() : Element("<AddExp>") {}
};
struct RelationalExpr : public Element {
explicit RelationalExpr() : Element("<RelExp>") {}
};
struct EqualExpr : public Element {
explicit EqualExpr() : Element("<EqExp>") {}
};
struct LogicalAndExpr : public Element {
explicit LogicalAndExpr() : Element("<LAndExp>") {}
};
struct LogicalOrExpr : public Element {
explicit LogicalOrExpr() : Element("<LOrExp>") {}
};
struct ConstExpr : public Element {
explicit ConstExpr() : Element("<ConstExp>") {}
};
#endif //CODE_ELEMENT_H