Convert Statement to use Ptr (#788)

Note this makes a few cases where the Statement was optional explicit (Block, If, Sequence). I do add a few CHECKs around where statements were optional and assumed but unverified.

I switch TypeCheckStmt to not take an optional Statement because I think it makes the call sites clearer in behavior. It's also a smaller change than the converse, because taking an optional Statement means the returned statement would also need to be optional. Arguably a wrapper for optional statements could be added, but this still seems cleaner to me, and there aren't that many cases of an optional statement.

Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
Jon Meow
2021-08-30 14:41:14 -07:00
committed by GitHub
co-authored by Geoff Romer
parent ed2d171703
commit 36ed79dc25
12 changed files with 166 additions and 138 deletions
+3 -3
View File
@@ -65,7 +65,7 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
if_stmt.ThenStmt()->PrintDepth(depth - 1, out);
if (if_stmt.ElseStmt()) {
out << "\nelse\n";
if_stmt.ElseStmt()->PrintDepth(depth - 1, out);
(*if_stmt.ElseStmt())->PrintDepth(depth - 1, out);
}
break;
}
@@ -87,7 +87,7 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
out << " ";
}
if (seq.Next()) {
seq.Next()->PrintDepth(depth - 1, out);
(*seq.Next())->PrintDepth(depth - 1, out);
}
break;
}
@@ -98,7 +98,7 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
out << "\n";
}
if (block.Stmt()) {
block.Stmt()->PrintDepth(depth, out);
(*block.Stmt())->PrintDepth(depth, out);
if (depth < 0 || depth > 1) {
out << "\n";
}