Add support for most kinds of declarations to be declared and used as namespace members (#2575)

Support for global variables is still missing; they're a bit more tricky because they use a pattern to introduce their name.

Prior to this change, explorer heavily relied on name comparisons to determine whether two declarations declare the same entity. Some of those instances are fixed in this PR, but more remain to be fixed, and some TODOs are added for some harder-to-fix instances.
This commit is contained in:
Richard Smith
2023-02-08 13:21:15 -08:00
committed by GitHub
parent 245e4d1ea6
commit 4fa71e32f5
604 changed files with 66695 additions and 5173 deletions
+6 -6
View File
@@ -236,24 +236,24 @@ auto GetName(const Declaration& declaration)
-> std::optional<std::string_view> {
switch (declaration.kind()) {
case DeclarationKind::NamespaceDeclaration:
return cast<NamespaceDeclaration>(declaration).name();
return cast<NamespaceDeclaration>(declaration).name().inner_name();
case DeclarationKind::FunctionDeclaration:
return cast<FunctionDeclaration>(declaration).name().inner_name();
case DeclarationKind::DestructorDeclaration:
return "destructor";
case DeclarationKind::ClassDeclaration:
return cast<ClassDeclaration>(declaration).name();
return cast<ClassDeclaration>(declaration).name().inner_name();
case DeclarationKind::MixinDeclaration: {
return cast<MixinDeclaration>(declaration).name();
return cast<MixinDeclaration>(declaration).name().inner_name();
}
case DeclarationKind::MixDeclaration: {
return std::nullopt;
}
case DeclarationKind::ChoiceDeclaration:
return cast<ChoiceDeclaration>(declaration).name();
return cast<ChoiceDeclaration>(declaration).name().inner_name();
case DeclarationKind::InterfaceDeclaration:
case DeclarationKind::ConstraintDeclaration:
return cast<ConstraintTypeDeclaration>(declaration).name();
return cast<ConstraintTypeDeclaration>(declaration).name().inner_name();
case DeclarationKind::VariableDeclaration:
return cast<VariableDeclaration>(declaration).binding().name();
case DeclarationKind::AssociatedConstantDeclaration:
@@ -266,7 +266,7 @@ auto GetName(const Declaration& declaration)
case DeclarationKind::SelfDeclaration:
return SelfDeclaration::name();
case DeclarationKind::AliasDeclaration: {
return cast<AliasDeclaration>(declaration).name();
return cast<AliasDeclaration>(declaration).name().inner_name();
}
}
}