mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -12,15 +12,19 @@ namespace Carbon {
|
||||
|
||||
void Builtins::Register(Nonnull<const Declaration*> decl) {
|
||||
if (const auto* interface = dyn_cast<InterfaceDeclaration>(decl)) {
|
||||
static std::map<std::string, int>* builtin_indexes = [] {
|
||||
std::map<std::string, int> builtin_indexes;
|
||||
if (interface->name().is_qualified()) {
|
||||
return;
|
||||
}
|
||||
|
||||
static std::map<std::string, int, std::less<>>* builtin_indexes = [] {
|
||||
std::map<std::string, int, std::less<>> builtin_indexes;
|
||||
for (int index = 0; index <= static_cast<int>(Builtin::Last); ++index) {
|
||||
builtin_indexes.emplace(BuiltinNames[index], index);
|
||||
}
|
||||
return new auto(std::move(builtin_indexes));
|
||||
}();
|
||||
|
||||
auto it = builtin_indexes->find(interface->name());
|
||||
auto it = builtin_indexes->find(interface->name().inner_name());
|
||||
if (it != builtin_indexes->end()) {
|
||||
builtins_[it->second] = interface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user