mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
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:
committed by
GitHub
co-authored by
Geoff Romer
parent
ed2d171703
commit
36ed79dc25
@@ -399,8 +399,14 @@ auto ValueEqual(const Value* v1, const Value* v2, SourceLocation loc) -> bool {
|
||||
return cast<BoolValue>(*v1).Val() == cast<BoolValue>(*v2).Val();
|
||||
case Value::Kind::PointerValue:
|
||||
return cast<PointerValue>(*v1).Val() == cast<PointerValue>(*v2).Val();
|
||||
case Value::Kind::FunctionValue:
|
||||
return cast<FunctionValue>(*v1).Body() == cast<FunctionValue>(*v2).Body();
|
||||
case Value::Kind::FunctionValue: {
|
||||
std::optional<Ptr<const Statement>> body1 =
|
||||
cast<FunctionValue>(*v1).Body();
|
||||
std::optional<Ptr<const Statement>> body2 =
|
||||
cast<FunctionValue>(*v2).Body();
|
||||
return body1.has_value() == body2.has_value() &&
|
||||
(!body1.has_value() || *body1 == *body2);
|
||||
}
|
||||
case Value::Kind::TupleValue:
|
||||
return FieldsValueEqual(cast<TupleValue>(*v1).Elements(),
|
||||
cast<TupleValue>(*v2).Elements(), loc);
|
||||
|
||||
Reference in New Issue
Block a user