mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:21:04 +01:00
Initial support for where expressions. (#1310)
Build constraint types from `where` expressions. This is very bare-bones; there's no support for constraining `.Self` or associated types yet, but degenerate cases not involving self-reference work. `==` constraints are syntactically supported but not semantically verified yet, and they aren't used for anything.
This commit is contained in:
@@ -171,6 +171,15 @@ void Expression::Print(llvm::raw_ostream& out) const {
|
||||
<< if_expr.then_expression() << " else " << if_expr.else_expression();
|
||||
break;
|
||||
}
|
||||
case ExpressionKind::WhereExpression: {
|
||||
const auto& where = cast<WhereExpression>(*this);
|
||||
out << where.base() << " where ";
|
||||
llvm::ListSeparator sep(" and ");
|
||||
for (const WhereClause* clause : where.clauses()) {
|
||||
out << sep << *clause;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ExpressionKind::InstantiateImpl: {
|
||||
const auto& inst_impl = cast<InstantiateImpl>(*this);
|
||||
out << "instantiate " << *inst_impl.generic_impl();
|
||||
@@ -246,6 +255,7 @@ void Expression::PrintID(llvm::raw_ostream& out) const {
|
||||
case ExpressionKind::SimpleMemberAccessExpression:
|
||||
case ExpressionKind::CompoundMemberAccessExpression:
|
||||
case ExpressionKind::IfExpression:
|
||||
case ExpressionKind::WhereExpression:
|
||||
case ExpressionKind::TupleLiteral:
|
||||
case ExpressionKind::StructLiteral:
|
||||
case ExpressionKind::StructTypeLiteral:
|
||||
@@ -261,4 +271,23 @@ void Expression::PrintID(llvm::raw_ostream& out) const {
|
||||
}
|
||||
}
|
||||
|
||||
WhereClause::~WhereClause() = default;
|
||||
|
||||
void WhereClause::Print(llvm::raw_ostream& out) const {
|
||||
switch (kind()) {
|
||||
case WhereClauseKind::IsWhereClause: {
|
||||
auto& clause = cast<IsWhereClause>(*this);
|
||||
out << clause.type() << " is " << clause.constraint();
|
||||
break;
|
||||
}
|
||||
case WhereClauseKind::EqualsWhereClause: {
|
||||
auto& clause = cast<EqualsWhereClause>(*this);
|
||||
out << clause.lhs() << " == " << clause.rhs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WhereClause::PrintID(llvm::raw_ostream& out) const { out << "..."; }
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user