-
Notifications
You must be signed in to change notification settings - Fork 1
/
ast_stmt.h
137 lines (106 loc) · 2.31 KB
/
ast_stmt.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
/* File: ast_stmt.h
* ----------------
* The Stmt class and its subclasses are used to represent
* statements in the parse tree. For each statment in the
* language (for, if, return, etc.) there is a corresponding
* node class for that construct.
*/
#ifndef _H_ast_stmt
#define _H_ast_stmt
#include "list.h"
#include "ast.h"
class Decl;
class VarDecl;
class Expr;
class Program : public Node
{
protected:
List<Decl*> *decls;
public:
Program(List<Decl*> *declList);
void Check();
void Emit();
};
class Stmt : public Node
{
public:
Stmt() : Node() {}
Stmt(yyltype loc) : Node(loc) {}
};
class StmtBlock : public Stmt
{
protected:
List<VarDecl*> *decls;
List<Stmt*> *stmts;
public:
StmtBlock(List<VarDecl*> *variableDeclarations, List<Stmt*> *statements);
void Check();
void Emit(CodeGenerator *cg);
};
class ConditionalStmt : public Stmt
{
protected:
Expr *test;
Stmt *body;
public:
ConditionalStmt(Expr *testExpr, Stmt *body);
void Check();
};
class LoopStmt : public ConditionalStmt
{
protected:
const char *afterLoopLabel;
public:
LoopStmt(Expr *testExpr, Stmt *body)
: ConditionalStmt(testExpr, body) {}
const char *GetLoopExitLabel() { return afterLoopLabel; }
};
class ForStmt : public LoopStmt
{
protected:
Expr *init, *step;
public:
ForStmt(Expr *init, Expr *test, Expr *step, Stmt *body);
void Emit(CodeGenerator *cg);
};
class WhileStmt : public LoopStmt
{
public:
WhileStmt(Expr *test, Stmt *body) : LoopStmt(test, body) {}
void Emit(CodeGenerator *cg);
};
class IfStmt : public ConditionalStmt
{
protected:
Stmt *elseBody;
public:
IfStmt(Expr *test, Stmt *thenBody, Stmt *elseBody);
void Check();
void Emit(CodeGenerator *cg);
};
class BreakStmt : public Stmt
{
public:
BreakStmt(yyltype loc) : Stmt(loc) {}
void Check();
void Emit(CodeGenerator *cg);
};
class ReturnStmt : public Stmt
{
protected:
Expr *expr;
public:
ReturnStmt(yyltype loc, Expr *expr);
void Check();
void Emit(CodeGenerator *cg);
};
class PrintStmt : public Stmt
{
protected:
List<Expr*> *args;
public:
PrintStmt(List<Expr*> *arguments);
void Check();
void Emit(CodeGenerator *cg);
};
#endif