Add support for return; (#678)

This creates a ReturnExpression. A separate change should enforce that an implicit return of `()` is only allowed in functions that have an implicit return type of `()`, and I think the structure taken here should ease that.
This commit is contained in:
Jon Meow
2021-08-02 16:30:08 -07:00
committed by GitHub
parent b1993a6cd0
commit 6ae9cc3cf8
16 changed files with 114 additions and 33 deletions
+3 -1
View File
@@ -60,6 +60,7 @@ struct If {
struct Return {
static constexpr StatementKind Kind = StatementKind::Return;
const Expression* exp;
bool is_omitted_exp;
};
struct Sequence {
@@ -120,7 +121,8 @@ struct Statement {
static auto MakeIf(int line_num, const Expression* cond,
const Statement* then_stmt, const Statement* else_stmt)
-> const Statement*;
static auto MakeReturn(int line_num, const Expression* e) -> const Statement*;
static auto MakeReturn(int line_num, const Expression* exp,
bool is_omitted_exp) -> const Statement*;
static auto MakeSequence(int line_num, const Statement* s1,
const Statement* s2) -> const Statement*;
static auto MakeBlock(int line_num, const Statement* s) -> const Statement*;