node_kind.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/sem_ir/node_kind.h"
  5. namespace Carbon::SemIR {
  6. CARBON_DEFINE_ENUM_CLASS_NAMES(NodeKind) = {
  7. #define CARBON_SEM_IR_NODE_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
  8. #include "toolchain/sem_ir/node_kind.def"
  9. };
  10. // Returns the name to use for this node kind in Semantics IR.
  11. [[nodiscard]] auto NodeKind::ir_name() const -> llvm::StringRef {
  12. static constexpr llvm::StringRef Table[] = {
  13. #define CARBON_SEM_IR_NODE_KIND_WITH_IR_NAME(Name, IR_Name) IR_Name,
  14. #include "toolchain/sem_ir/node_kind.def"
  15. };
  16. return Table[AsInt()];
  17. }
  18. auto NodeKind::value_kind() const -> NodeValueKind {
  19. static constexpr NodeValueKind Table[] = {
  20. #define CARBON_SEM_IR_NODE_KIND_WITH_VALUE_KIND(Name, Kind) NodeValueKind::Kind,
  21. #include "toolchain/sem_ir/node_kind.def"
  22. };
  23. return Table[AsInt()];
  24. }
  25. auto NodeKind::terminator_kind() const -> TerminatorKind {
  26. static constexpr TerminatorKind Table[] = {
  27. #define CARBON_SEM_IR_NODE_KIND_WITH_TERMINATOR_KIND(Name, Kind) \
  28. TerminatorKind::Kind,
  29. #include "toolchain/sem_ir/node_kind.def"
  30. };
  31. return Table[AsInt()];
  32. }
  33. } // namespace Carbon::SemIR