mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 16:30:36 +00:00
Following up on discussion from #3948, doing a general rename of "enclosing scope" to "parent scope" (and "enclosing scopes" to "ancestor scopes"). The intent is to improve understandability and collide less with C++ terminology for "enclosing scope". Note this changes most uses of "enclosing", but leaves behind a few like "enclosing function" and "enclosing block". Note this does create some "parent class" mentions for "adapt" and "var" (the class they're within), which is maybe unfortunate, but we'd probably say "base class" if we meant inheritance so perhaps that's okay. Along the same lines, these are the only `parent_class` uses I see now, and we do have a few `base_class`.
77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_SEM_IR_BIND_NAME_H_
|
|
#define CARBON_TOOLCHAIN_SEM_IR_BIND_NAME_H_
|
|
|
|
#include "common/hashing.h"
|
|
#include "toolchain/base/value_store.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
struct BindNameInfo : public Printable<BindNameInfo> {
|
|
auto Print(llvm::raw_ostream& out) const -> void {
|
|
out << "{name: " << name_id << ", parent_scope: " << parent_scope_id
|
|
<< ", index: " << bind_index << "}";
|
|
}
|
|
|
|
// The name.
|
|
NameId name_id;
|
|
// The parent scope.
|
|
NameScopeId parent_scope_id;
|
|
// The index for a compile-time binding. Invalid for a runtime binding.
|
|
CompileTimeBindIndex bind_index;
|
|
};
|
|
|
|
// Hashing for BindNameInfo. See common/hashing.h.
|
|
inline auto CarbonHashValue(const BindNameInfo& value, uint64_t seed)
|
|
-> HashCode {
|
|
Hasher hasher(seed);
|
|
hasher.Hash(value);
|
|
return static_cast<HashCode>(hasher);
|
|
}
|
|
|
|
// DenseMapInfo for BindNameInfo.
|
|
struct BindNameInfoDenseMapInfo {
|
|
static auto getEmptyKey() -> BindNameInfo {
|
|
return BindNameInfo{.name_id = NameId::Invalid,
|
|
.parent_scope_id = NameScopeId::Invalid,
|
|
.bind_index = CompileTimeBindIndex(
|
|
CompileTimeBindIndex::InvalidIndex - 1)};
|
|
}
|
|
static auto getTombstoneKey() -> BindNameInfo {
|
|
return BindNameInfo{.name_id = NameId::Invalid,
|
|
.parent_scope_id = NameScopeId::Invalid,
|
|
.bind_index = CompileTimeBindIndex(
|
|
CompileTimeBindIndex::InvalidIndex - 2)};
|
|
}
|
|
static auto getHashValue(const BindNameInfo& val) -> unsigned {
|
|
return static_cast<uint64_t>(HashValue(val));
|
|
}
|
|
static auto isEqual(const BindNameInfo& lhs, const BindNameInfo& rhs)
|
|
-> bool {
|
|
return std::memcmp(&lhs, &rhs, sizeof(BindNameInfo)) == 0;
|
|
}
|
|
};
|
|
|
|
// Value store for BindNameInfo. In addition to the regular ValueStore
|
|
// functionality, this can provide optional canonical IDs for BindNameInfos.
|
|
struct BindNameStore : public ValueStore<BindNameId> {
|
|
public:
|
|
// Convert an ID to a canonical ID. All calls to this with equivalent
|
|
// `BindNameInfo`s will return the same `BindNameId`.
|
|
auto MakeCanonical(BindNameId id) -> BindNameId {
|
|
return canonical_ids_.insert({Get(id), id}).first->second;
|
|
}
|
|
|
|
private:
|
|
llvm::DenseMap<BindNameInfo, BindNameId, BindNameInfoDenseMapInfo>
|
|
canonical_ids_;
|
|
};
|
|
|
|
} // namespace Carbon::SemIR
|
|
|
|
#endif // CARBON_TOOLCHAIN_SEM_IR_BIND_NAME_H_
|