builtin_inst_kind.def 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. //
  5. // This is an X-macro header. It does not use `#include` guards, and instead is
  6. // designed to be `#include`ed after the x-macro is defined in order for its
  7. // inclusion to expand to the desired output. Macro definitions are cleaned up
  8. // at the end of this file.
  9. //
  10. // Supported x-macros are:
  11. // - CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
  12. // Used as a fallback if other macros are missing. Used directly by Invalid
  13. // only, which is defined last.
  14. // - CARBON_SEM_IR_BUILTIN_INST_KIND(Name, Label)
  15. // Defines a non-Invalid builtin type. The label is used for stringifying
  16. // types.
  17. //
  18. // This tree represents the subset relationship between these macros, where if a
  19. // specific x-macro isn't defined, it'll fall back to the parent macro.
  20. #if !(defined(CARBON_SEM_IR_BUILTIN_INST_KIND_NAME) || \
  21. defined(CARBON_SEM_IR_BUILTIN_INST_KIND))
  22. #error \
  23. "Must define CARBON_SEM_IR_BUILTIN_INST_KIND family x-macros to use this file."
  24. #endif
  25. // If CARBON_SEM_IR_BUILTIN_INST_KIND_NAME is undefined, ignore calls.
  26. #ifndef CARBON_SEM_IR_BUILTIN_INST_KIND_NAME
  27. #define CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
  28. #endif
  29. // If CARBON_SEM_IR_BUILTIN_INST_KIND is undefined, delegate calls to
  30. // CARBON_SEM_IR_BUILTIN_INST_KIND_NAME.
  31. #ifndef CARBON_SEM_IR_BUILTIN_INST_KIND
  32. #define CARBON_SEM_IR_BUILTIN_INST_KIND(Name, ...) \
  33. CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Name)
  34. #endif
  35. // Tracks expressions which are valid as types.
  36. // This has a deliberately self-referential type.
  37. CARBON_SEM_IR_BUILTIN_INST_KIND(TypeType, "type")
  38. // Used when a semantic error has been detected, and a SemIR InstId is still
  39. // required. For example, when there is a type checking issue, this will be used
  40. // in the type_id. It's typically used as a cue that semantic checking doesn't
  41. // need to issue further diagnostics.
  42. CARBON_SEM_IR_BUILTIN_INST_KIND(Error, "<error>")
  43. // Used for the type of patterns that do not match a fixed type.
  44. CARBON_SEM_IR_BUILTIN_INST_KIND(AutoType, "auto")
  45. // -----------------------------------------------------------------------------
  46. // TODO: Below types are all placeholders. While the above may last, the below
  47. // are expected to need to change in order to better reflect Carbon's design.
  48. // Keeping distinct placeholders can help find usages for later fixes.
  49. // -----------------------------------------------------------------------------
  50. // The type of bool literals and branch conditions, bool.
  51. CARBON_SEM_IR_BUILTIN_INST_KIND(BoolType, "bool")
  52. // The type of integer values and integer literals, currently always i32.
  53. CARBON_SEM_IR_BUILTIN_INST_KIND(IntType, "i32")
  54. // The type of floating point values and real literals, currently always f64.
  55. CARBON_SEM_IR_BUILTIN_INST_KIND(FloatType, "f64")
  56. // The type of string values and String literals.
  57. CARBON_SEM_IR_BUILTIN_INST_KIND(StringType, "String")
  58. // The type of bound method values.
  59. CARBON_SEM_IR_BUILTIN_INST_KIND(BoundMethodType, "<bound method>")
  60. // The type of specific functions.
  61. CARBON_SEM_IR_BUILTIN_INST_KIND(SpecificFunctionType, "<specific function>")
  62. // The type of namespace and imported package names.
  63. CARBON_SEM_IR_BUILTIN_INST_KIND(NamespaceType, "<namespace>")
  64. // The type of witnesses.
  65. CARBON_SEM_IR_BUILTIN_INST_KIND(WitnessType, "<witness>")
  66. // The type of virtual function tables
  67. CARBON_SEM_IR_BUILTIN_INST_KIND(VtableType, "<vtable>")
  68. // Keep invalid last, so that we can use values as array indices without needing
  69. // an invalid entry.
  70. CARBON_SEM_IR_BUILTIN_INST_KIND_NAME(Invalid)
  71. #undef CARBON_SEM_IR_BUILTIN_INST_KIND_NAME
  72. #undef CARBON_SEM_IR_BUILTIN_INST_KIND