mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:04:05 +00:00
Restructure ArgAndKind as a type-safe generic ID. (#7172)
The key changes here are: - Relocating and renaming it to align with `IdKind` (and relocating `ToRaw` and `FromRaw` to follow it). - Adding a `Dispatch` method that provides a generic overload-based API for expressing per-ID-kind dispatch, and rewriting existing code to use it. Note in particular that using overloads instead of switch cases makes it possible to generically handle all specializations of a templated ID type, e.g. `SomeIdType<T>` for all `T`. We have no such templated ID types yet, but I'm introducing one in a follow-up PR that needs this capability.
This commit is contained in:
1 parent
db24042fe5
commit
daebbf32fa
10 files changed
+236
-218
No files matched your search
@@ -1052,8 +1052,16 @@ auto Formatter::FormatNameAndForm(InstId inst_id, Inst inst) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto Formatter::FormatInstArgAndKind(Inst::ArgAndKind arg_and_kind) -> void {
|
||||
GetFormatArgFn(arg_and_kind.kind())(*this, arg_and_kind.value());
|
||||
auto Formatter::FormatInstArgAndKind(IdAndKind arg_and_kind) -> void {
|
||||
arg_and_kind.Dispatch<void>([this]<typename IdT>(IdT arg) {
|
||||
if constexpr (requires { FormatArg(arg); }) {
|
||||
FormatArg(arg);
|
||||
} else if constexpr (std::is_same_v<IdT, IdAndKind::NoneType>) {
|
||||
// Do nothing
|
||||
} else {
|
||||
CARBON_FATAL("Missing FormatArg for {0}", typeid(IdT).name());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
auto Formatter::FormatInstRhs(Inst inst) -> void {
|
||||
|
||||
Reference in new issue
Block a user