-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.h
executable file
·186 lines (176 loc) · 3.33 KB
/
expr.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
#pragma once
#include "common.h"
#include "type_value.h"
#include "var_record.h"
#include "labelmanager.h"
#define UNDEFINE_EXPR "undefine_expr"
#define BASE_EXPR_TYPE "base_type"
#define UNARY_EXPR_TYPE "unary_type"
#define BINARY_EXPR_TYPE "binary_type"
#define CONST_EXPR_TYPE "leaf_node_value"
#define ID_EXPR_TYPE "id_node_value"
#define RECORD_EXPR_TYPE "record_node_value"
#define ARR_EXPR_TYPE "arr_node_value"
#define FUNC_EXPR_TYPE "func_node_value"
class base_expr{
public:
string codestr;
bool flag;
string type;
string gettype(){
return type;
}
bool type_id;//表达式结果 整数或则浮点 true表示浮点数
base_expr(){
codestr = UNDEFINE_EXPR;
flag = false;
type = BASE_EXPR_TYPE;
}
virtual int gencode(bool _double = false){
}//return the value is store in?
void setcodestr(const string & _codestr){
codestr = _codestr;
}
virtual ~base_expr(){
}
virtual bool isconst(){
}
virtual bool isstr(){
return false;
}
virtual bool isconststr(string & s){
return false;
}
virtual bool isdouble(){
return false;
}
virtual bool checktype(bool _double ){
}
virtual bool isleaf(){
return true;
}
};
class unary_expr: public base_expr{
public:
int op;
shared_ptr <base_expr> child;
int gencode(bool _double);
unary_expr(){
type = UNARY_EXPR_TYPE;
}
bool isconst(){
return child -> isconst();
}
bool isdouble(){
return child -> isdouble();
}
bool checktype(bool _double){
return child -> checktype(_double);
}
bool isleaf(){
return false;
}
};
class binary_expr: public base_expr{
public:
int op;
shared_ptr <base_expr> lchild;
shared_ptr <base_expr> rchild;
int gencode(bool _double);
binary_expr(){
type = BINARY_EXPR_TYPE;
}
bool isconst(){
return lchild -> isconst() && rchild -> isconst();
}
bool isdouble(){
return lchild -> isdouble() && rchild -> isdouble();
}
bool checktype(bool _double){
return lchild -> checktype(_double) && rchild -> checktype(_double);
}
bool isleaf(){
return false;
}
};
class leaf_node_value: public base_expr{
public:
value_set value;
int type_id;
int gencode(bool _double);
leaf_node_value(){
type = CONST_EXPR_TYPE;
}
bool isconst(){
return true;
}
bool isstr(){
if(type_id == STR_TYPE){
return true;
}
else
return false;
}
bool isconststr(string & s){
if(type_id == STR_TYPE){
s = value._str;
return true;
}
else
return false;
}
bool isdouble(){
return type_id == REAL_TYPE;
}
bool checktype(bool _double){
if(_double)
return type_id == REAL_TYPE || type_id == INT_TYPE;
else
return type_id == INT_TYPE;
}
};
class record_node_value: public base_expr{
public:
string id;
string member;
int gencode(bool _double);
record_node_value(){
type = RECORD_EXPR_TYPE;
}
bool isconst(){
return false;
}
bool isstr();
bool isdouble();
bool checktype(bool _double);
};
class id_node_value: public base_expr{
public:
string id;
id_node_value(){
type = ID_EXPR_TYPE;
}
int gencode(bool _double);
bool isconst(){
return false;
}
bool isstr();
bool isdouble();
bool checktype(bool _double);
};
class arr_node_value: public base_expr{
public:
string id;
shared_ptr <base_expr> index;
arr_node_value(){
type = ARR_EXPR_TYPE;
}
int gencode(bool _double);
bool expr_value_type();
bool isconst(){
return false;
}
bool isstr();
bool isdouble();
bool checktype(bool _double);
};