Basic support for match_first declarations. (#2523)

Add basic support for `match_first` declarations to explorer, as described in https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#prioritization-rule. The concrete syntax here is not yet approved, so `match_first` is renamed to `__match_first` for now, but the semantics are necessary to implement other approved features in explorer so we're intentionally getting a little ahead of the design here.
This commit is contained in:
Richard Smith
2023-01-17 13:08:38 -08:00
committed by GitHub
parent 08a289753c
commit 74aae0911f
16 changed files with 261 additions and 4 deletions
+14
View File
@@ -36,6 +36,16 @@ void Declaration::Print(llvm::raw_ostream& out) const {
out << "}\n";
break;
}
case DeclarationKind::MatchFirstDeclaration: {
const auto& match_first_decl = cast<MatchFirstDeclaration>(*this);
PrintID(out);
out << " {\n";
for (Nonnull<const ImplDeclaration*> m : match_first_decl.impls()) {
out << *m;
}
out << "}\n";
break;
}
case DeclarationKind::FunctionDeclaration:
cast<FunctionDeclaration>(*this).PrintDepth(-1, out);
break;
@@ -139,6 +149,9 @@ void Declaration::PrintID(llvm::raw_ostream& out) const {
<< impl_decl.interface();
break;
}
case DeclarationKind::MatchFirstDeclaration:
out << "match_first";
break;
case DeclarationKind::FunctionDeclaration:
out << "fn " << cast<FunctionDeclaration>(*this).name();
break;
@@ -232,6 +245,7 @@ auto GetName(const Declaration& declaration)
case DeclarationKind::InterfaceExtendsDeclaration:
case DeclarationKind::InterfaceImplDeclaration:
case DeclarationKind::ImplDeclaration:
case DeclarationKind::MatchFirstDeclaration:
return std::nullopt;
case DeclarationKind::SelfDeclaration:
return SelfDeclaration::name();