mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
This follows up on a discussion about wanting to use `Any*` inst clusters to handle boilerplate construction, with the issue that `UncheckedLoc` use removes validation. Some context is at https://github.com/carbon-language/carbon-lang/pull/6930#discussion_r2963157428. This folds in `MakeImportedLocIdAndInst` because the logic is related, particularly for `LocId` values which are `ImportIRInstId`, and it eliminates questions of what the right function is to use. This uncovers an error in the `NodeKind` associated with `FormBindingPattern`. For now I'm just adding a TODO regarding that. Assisted-by: Google Antigravity with Gemini
41 lines
1.3 KiB
C++
41 lines
1.3 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
|
|
|
|
#include "toolchain/sem_ir/inst_kind.h"
|
|
|
|
#include "toolchain/sem_ir/typed_insts.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
CARBON_DEFINE_ENUM_CLASS_NAMES(InstKind) {
|
|
#define CARBON_SEM_IR_INST_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
|
|
#include "toolchain/sem_ir/inst_kind.def"
|
|
};
|
|
|
|
auto InstKind::definition_info(InstKind inst_kind) -> const DefinitionInfo& {
|
|
static constexpr InstKind::DefinitionInfo DefinitionInfos[] = {
|
|
#define CARBON_SEM_IR_INST_KIND(Name) SemIR::Name::Kind.info_,
|
|
#include "toolchain/sem_ir/inst_kind.def"
|
|
};
|
|
return DefinitionInfos[inst_kind.AsInt()];
|
|
}
|
|
|
|
auto InstKind::has_type() const -> bool {
|
|
static constexpr bool Table[] = {
|
|
#define CARBON_SEM_IR_INST_KIND(Name) Internal::HasTypeIdMember<SemIR::Name>,
|
|
#include "toolchain/sem_ir/inst_kind.def"
|
|
};
|
|
return Table[AsInt()];
|
|
}
|
|
|
|
auto InstKind::IsAllowedNodeKind(Parse::NodeKind node_kind) const -> bool {
|
|
const auto& def = definition_info(*this);
|
|
if (def.internal_allow_all_node_kinds) {
|
|
return true;
|
|
}
|
|
return llvm::is_contained(def.internal_allowed_node_kinds, node_kind);
|
|
}
|
|
|
|
} // namespace Carbon::SemIR
|