-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpr.h
More file actions
49 lines (39 loc) · 916 Bytes
/
expr.h
File metadata and controls
49 lines (39 loc) · 916 Bytes
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
#ifndef __expr_h__
#define __expr_h__
#include "node.h"
#include "type.h"
class Token;
class Expr : public Node{
public:
Token *op;
Type *type;
Expr(Token *tok , Type *p){
op = tok;
type = p;
}
~Expr(){
}
virtual Expr * gen(){
return this;
}
virtual Expr * reduce(){
return this;
}
virtual std::string toString(){
return op->toString();
}
void emitjumps(std::string test , int t , int f){
if(t != 0 && f != 0){
emit("if" + test + " goto L" + std::to_string(t));
emit("goto L" + std::to_string(f));
}else if(t != 0){
emit("if " + test + " goto L" + std::to_string(t));
}else if(f != 0){
emit("iffalse " + test + " goto L" + std::to_string(f));
}
}
void jumping(int t ,int f){
emitjumps(toString(),t,f);
}
};
#endif