mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user