-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlflow.h
117 lines (93 loc) · 3.29 KB
/
controlflow.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 "ast.h"
#include "functions.h"
class GotoAST : public ExprAST {
public:
GotoAST(Token tok, BasicContext* ctx, std::string label)
: ExprAST(std::move(tok), ctx), _label(label) {}
llvm::Value* codegen() override;
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
private:
std::string _label;
};
class GosubAST : public ExprAST {
public:
GosubAST(Token tok, BasicContext* ctx, std::string label)
: ExprAST(std::move(tok), ctx), _label(label) {}
llvm::Value* codegen() override;
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
private:
std::string _label;
};
std::unique_ptr<FunctionCallAST> makeGosubCall(const Token& tok,
BasicContext* ctx,
std::string name);
std::unique_ptr<ProtoDefAST> makeGosubProto(const LabelAST* label);
class ForAST : public ExprAST {
public:
llvm::Value* codegen() override;
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
ForAST(Token tok,
BasicContext* ctx,
std::unique_ptr<ExprAST> controlVar,
std::unique_ptr<ExprAST> toExpr,
std::unique_ptr<ExprAST> stepExpr,
std::unique_ptr<ExprAST> bodyExpr)
: ExprAST(std::move(tok), ctx),
_controlVar(std::move(controlVar)),
_toExpr(std::move(toExpr)),
_stepExpr(std::move(stepExpr)),
_bodyExpr(std::move(bodyExpr)) {}
private:
LetAST* _getControlVar() const;
std::unique_ptr<ExprAST> _controlVar, _toExpr, _stepExpr, _bodyExpr;
};
class WhileAST : public ExprAST {
public:
WhileAST(Token tok,
BasicContext* ctx,
std::unique_ptr<ExprAST> condExpr,
bool isNot,
std::unique_ptr<ExprAST> body)
: ExprAST(std::move(tok), ctx),
_condExpr(std::move(condExpr)),
_isNot(isNot),
_body(std::move(body)) {}
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
llvm::Value* codegen() override;
private:
std::unique_ptr<ExprAST> _condExpr;
bool _isNot;
std::unique_ptr<ExprAST> _body;
};
class DoAST : public ExprAST {
public:
DoAST(Token tok,
BasicContext* ctx,
std::unique_ptr<ExprAST> condExpr,
std::unique_ptr<ExprAST> body)
: ExprAST(std::move(tok), ctx), _condExpr(std::move(condExpr)), _body(std::move(body)) {}
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
llvm::Value* codegen() override;
private:
std::unique_ptr<ExprAST> _condExpr;
std::unique_ptr<ExprAST> _body;
};
class IfAST : public ExprAST {
public:
IfAST(Token tok,
BasicContext* ctx,
std::unique_ptr<ExprAST> condition,
std::unique_ptr<ExprAST> then,
std::unique_ptr<ExprAST> elseExpr)
: ExprAST(std::move(tok), ctx),
_condition(std::move(condition)),
_then(std::move(then)),
_else(std::move(elseExpr)) {}
llvm::Value* codegen() override;
static std::unique_ptr<ExprAST> parse(const Token& tok, BasicContext* ctx);
private:
std::unique_ptr<ExprAST> _condition;
std::unique_ptr<ExprAST> _then;
std::unique_ptr<ExprAST> _else;
};