Initial implementation of returned var. (#1348)

This PR implements the `returned var` for the explorer.
- Enabled `returned var` and `return var` syntax in lexer and parser.
- Split `Return` statement into `ReturnVar` and `ReturnExpression` to distinguish the two types of returns.
- Added logic in name resolution, type checking and interpretation to process `returned var` definition and `ReturnVar` statement.
This commit is contained in:
SlaterLatiao
2022-07-06 13:35:41 -07:00
committed by GitHub
parent a23f15e901
commit 9106e9239e
29 changed files with 544 additions and 61 deletions
+9 -2
View File
@@ -50,6 +50,9 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
break;
case StatementKind::VariableDefinition: {
const auto& var = cast<VariableDefinition>(*this);
if (var.is_returned()) {
out << "returned ";
}
out << "var " << var.pattern() << " = " << var.init() << ";";
break;
}
@@ -71,8 +74,12 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
}
break;
}
case StatementKind::Return: {
const auto& ret = cast<Return>(*this);
case StatementKind::ReturnVar: {
out << "return var;";
break;
}
case StatementKind::ReturnExpression: {
const auto& ret = cast<ReturnExpression>(*this);
if (ret.is_omitted_expression()) {
out << "return;";
} else {