mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Implement support for named constraints (#2359)
Basic support for named constraints as described in [the generics design](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#named-constraints). Support is provided for `extends` and `impl` declarations in `constraint`, but not yet for member aliases. The missing prelude named constraints `Add`, `Mul`, `Ordered`, etc. are also added.
This commit is contained in:
@@ -15,8 +15,9 @@ Declaration::~Declaration() = default;
|
||||
|
||||
void Declaration::Print(llvm::raw_ostream& out) const {
|
||||
switch (kind()) {
|
||||
case DeclarationKind::InterfaceDeclaration: {
|
||||
const auto& iface_decl = cast<InterfaceDeclaration>(*this);
|
||||
case DeclarationKind::InterfaceDeclaration:
|
||||
case DeclarationKind::ConstraintDeclaration: {
|
||||
const auto& iface_decl = cast<ConstraintTypeDeclaration>(*this);
|
||||
PrintID(out);
|
||||
out << " {\n";
|
||||
for (Nonnull<Declaration*> m : iface_decl.members()) {
|
||||
@@ -120,6 +121,11 @@ void Declaration::PrintID(llvm::raw_ostream& out) const {
|
||||
out << "interface " << iface_decl.name();
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ConstraintDeclaration: {
|
||||
const auto& constraint_decl = cast<ConstraintDeclaration>(*this);
|
||||
out << "constraint " << constraint_decl.name();
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ImplDeclaration: {
|
||||
const auto& impl_decl = cast<ImplDeclaration>(*this);
|
||||
switch (impl_decl.kind()) {
|
||||
@@ -217,7 +223,8 @@ auto GetName(const Declaration& declaration)
|
||||
case DeclarationKind::ChoiceDeclaration:
|
||||
return cast<ChoiceDeclaration>(declaration).name();
|
||||
case DeclarationKind::InterfaceDeclaration:
|
||||
return cast<InterfaceDeclaration>(declaration).name();
|
||||
case DeclarationKind::ConstraintDeclaration:
|
||||
return cast<ConstraintTypeDeclaration>(declaration).name();
|
||||
case DeclarationKind::VariableDeclaration:
|
||||
return cast<VariableDeclaration>(declaration).binding().name();
|
||||
case DeclarationKind::AssociatedConstantDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user