13
13
#include " lexer.h"
14
14
#include " utils.h"
15
15
16
- // #include <llvm/IR/Function.h>
16
+ /* *
17
+ * @brief Include `llvm/IR/Function.h`
18
+ *
19
+ *
20
+ */
17
21
namespace llvm {
18
22
class Function ;
19
23
}
20
- // #include <llvm/IR/Value.h>
24
+
25
+ /* *
26
+ * @brief Include `llvm/IR/Value.h`
27
+ *
28
+ *
29
+ */
21
30
namespace llvm {
22
31
class Value ;
23
32
}
24
33
25
34
extern SourceLocation CurLoc;
26
35
27
- // / ExprAST - Base class for all expression nodes.
36
+ /* *
37
+ * @brief Base class for all expression nodes.
38
+ *
39
+ *
40
+ */
28
41
class ExprAST {
29
42
SourceLocation Loc;
30
43
31
44
public:
45
+ /* *
46
+ * @param Loc
47
+ */
32
48
ExprAST (SourceLocation Loc = CurLoc) : Loc(Loc) {}
33
49
virtual ~ExprAST () = default ;
34
50
virtual llvm::Value* codegen () = 0;
@@ -43,9 +59,17 @@ class ExprAST {
43
59
}
44
60
};
45
61
46
- // / NumberExprAST - Expression class for numeric literals like "1.0".
62
+ /* *
63
+ * @brief Expression class for numeric literals like "1.0".
64
+ *
65
+ *
66
+ */
47
67
class NumberExprAST : public ExprAST {
48
68
public:
69
+ /* *
70
+ *
71
+ * @return
72
+ */
49
73
double Val;
50
74
NumberExprAST (double Val) : Val(Val) {}
51
75
llvm::raw_ostream& dump (llvm::raw_ostream& out, int ind) override {
@@ -54,11 +78,18 @@ class NumberExprAST : public ExprAST {
54
78
llvm::Value* codegen () override ;
55
79
};
56
80
57
- // / VariableExprAST - Expression class for referencing a variable, like "a".
81
+ /* *
82
+ * @brief Expression class for referencing a variable, like "a".
83
+ *
84
+ */
58
85
class VariableExprAST : public ExprAST {
59
86
std::string Name;
60
87
61
88
public:
89
+ /* *
90
+ * @param Loc
91
+ * @param Name
92
+ */
62
93
VariableExprAST (SourceLocation Loc, std::string Name)
63
94
: ExprAST(Loc), Name(std::move(Name)) {}
64
95
const std::string& getName () const {
@@ -70,12 +101,19 @@ class VariableExprAST : public ExprAST {
70
101
}
71
102
};
72
103
73
- // / UnaryExprAST - Expression class for a unary operator.
104
+ /* *
105
+ * @brief Expression class for a unary operator.
106
+ *
107
+ */
74
108
class UnaryExprAST : public ExprAST {
75
109
char Opcode;
76
110
std::unique_ptr<ExprAST> Operand;
77
111
78
112
public:
113
+ /* *
114
+ * @param Opcode
115
+ * @param Operand
116
+ */
79
117
UnaryExprAST (char Opcode, std::unique_ptr<ExprAST> Operand)
80
118
: Opcode(Opcode), Operand(std::move(Operand)) {}
81
119
llvm::Value* codegen () override ;
@@ -86,12 +124,21 @@ class UnaryExprAST : public ExprAST {
86
124
}
87
125
};
88
126
89
- // / BinaryExprAST - Expression class for a binary operator.
127
+ /* *
128
+ * @brief Expression class for a binary operator.
129
+ *
130
+ */
90
131
class BinaryExprAST : public ExprAST {
91
132
char Op;
92
133
std::unique_ptr<ExprAST> LHS, RHS;
93
134
94
135
public:
136
+ /* *
137
+ * @param Loc
138
+ * @param Op
139
+ * @param LHS
140
+ * @param RHS
141
+ */
95
142
BinaryExprAST (
96
143
SourceLocation Loc,
97
144
char Op,
@@ -107,12 +154,20 @@ class BinaryExprAST : public ExprAST {
107
154
}
108
155
};
109
156
110
- // / CallExprAST - Expression class for function calls.
157
+ /* *
158
+ * @brief Expression class for function calls.
159
+ *
160
+ */
111
161
class CallExprAST : public ExprAST {
112
162
std::string Callee;
113
163
std::vector<std::unique_ptr<ExprAST>> Args;
114
164
115
165
public:
166
+ /* *
167
+ * @param Loc
168
+ * @param Callee
169
+ * @param Args
170
+ */
116
171
CallExprAST (
117
172
SourceLocation Loc,
118
173
std::string Callee,
@@ -127,11 +182,20 @@ class CallExprAST : public ExprAST {
127
182
}
128
183
};
129
184
130
- // / IfExprAST - Expression class for if/then/else.
185
+ /* *
186
+ * @brief Expression class for if/then/else.
187
+ *
188
+ */
131
189
class IfExprAST : public ExprAST {
132
190
std::unique_ptr<ExprAST> Cond, Then, Else;
133
191
134
192
public:
193
+ /* *
194
+ * @param Loc
195
+ * @param Cond
196
+ * @param Then
197
+ * @param Else
198
+ */
135
199
IfExprAST (
136
200
SourceLocation Loc,
137
201
std::unique_ptr<ExprAST> Cond,
@@ -151,12 +215,23 @@ class IfExprAST : public ExprAST {
151
215
}
152
216
};
153
217
154
- // / ForExprAST - Expression class for for/in.
218
+ /* *
219
+ * @brief Expression class for for/in.
220
+ *
221
+ *
222
+ */
155
223
class ForExprAST : public ExprAST {
156
224
std::string VarName;
157
225
std::unique_ptr<ExprAST> Start, End, Step, Body;
158
226
159
227
public:
228
+ /* *
229
+ * @param VarName
230
+ * @param Start
231
+ * @param End
232
+ * @param Step
233
+ * @param Body
234
+ */
160
235
ForExprAST (
161
236
std::string VarName,
162
237
std::unique_ptr<ExprAST> Start,
@@ -179,12 +254,20 @@ class ForExprAST : public ExprAST {
179
254
}
180
255
};
181
256
182
- // / VarExprAST - Expression class for var/in
257
+ /* *
258
+ * @brief Expression class for var/in
259
+ *
260
+ *
261
+ */
183
262
class VarExprAST : public ExprAST {
184
263
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames;
185
264
std::unique_ptr<ExprAST> Body;
186
265
187
266
public:
267
+ /* *
268
+ * @param VarNames
269
+ * @param Body
270
+ */
188
271
VarExprAST (
189
272
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
190
273
std::unique_ptr<ExprAST> Body)
@@ -200,9 +283,12 @@ class VarExprAST : public ExprAST {
200
283
}
201
284
};
202
285
203
- // / PrototypeAST - This class represents the "prototype" for a function,
204
- // / which captures its name, and its argument names (thus implicitly the number
205
- // / of arguments the function takes), as well as if it is an operator.
286
+ /* *
287
+ @brief This class represents the "prototype" for a function.
288
+
289
+ Captures a function's name, and its argument names (thus implicitly the number
290
+ of arguments the function takes), as well as if it is an operator.
291
+ */
206
292
class PrototypeAST {
207
293
std::string Name;
208
294
std::vector<std::string> Args;
@@ -211,6 +297,13 @@ class PrototypeAST {
211
297
int Line;
212
298
213
299
public:
300
+ /* *
301
+ * @param Loc
302
+ * @param Name
303
+ * @param Args
304
+ * @param IsOperator
305
+ * @param Prec
306
+ */
214
307
PrototypeAST (
215
308
SourceLocation Loc,
216
309
std::string Name,
@@ -248,12 +341,20 @@ class PrototypeAST {
248
341
}
249
342
};
250
343
251
- // / FunctionAST - This class represents a function definition itself.
344
+ /* *
345
+ * @brief This class represents a function definition itself.
346
+ *
347
+ *
348
+ */
252
349
class FunctionAST {
253
350
std::unique_ptr<PrototypeAST> Proto;
254
351
std::unique_ptr<ExprAST> Body;
255
352
256
353
public:
354
+ /* *
355
+ * @param Proto
356
+ * @param Body
357
+ */
257
358
FunctionAST (
258
359
std::unique_ptr<PrototypeAST> Proto, std::unique_ptr<ExprAST> Body)
259
360
: Proto(std::move(Proto)), Body(std::move(Body)) {}
@@ -274,7 +375,7 @@ std::unique_ptr<FunctionAST> ParseTopLevelExpr();
274
375
275
376
std::unique_ptr<ExprAST> ParsePrimary ();
276
377
277
- /* declared as extern for testing * /
378
+ // declared as extern for testing / /
278
379
std::unique_ptr<ExprAST> ParseExpression ();
279
380
std::unique_ptr<IfExprAST> ParseIfExpr ();
280
381
std::unique_ptr<NumberExprAST> ParseNumberExpr ();
0 commit comments