semantics_builtin_kind.def 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_SEMANTICS_BUILTIN_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_SEMANTICS_BUILTIN_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_SEMANTICS_BUILTIN_KIND_NAME) || \
  21. defined(CARBON_SEMANTICS_BUILTIN_KIND))
  22. #error \
  23. "Must define CARBON_SEMANTICS_BUILTIN_KIND family x-macros to use this file."
  24. #endif
  25. // If CARBON_SEMANTICS_BUILTIN_KIND_NAME is undefined, ignore calls.
  26. #ifndef CARBON_SEMANTICS_BUILTIN_KIND_NAME
  27. #define CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
  28. #endif
  29. // If CARBON_SEMANTICS_BUILTIN_KIND is undefined, delegate calls to
  30. // CARBON_SEMANTICS_BUILTIN_KIND_NAME.
  31. #ifndef CARBON_SEMANTICS_BUILTIN_KIND
  32. #define CARBON_SEMANTICS_BUILTIN_KIND(Name, ...) \
  33. CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
  34. #endif
  35. // Tracks expressions which are valid as types.
  36. // This has a deliberately self-referential type.
  37. CARBON_SEMANTICS_BUILTIN_KIND(TypeType, "Type")
  38. // Used when a SemanticNode has an invalid type, which should then be ignored
  39. // for future type checking.
  40. CARBON_SEMANTICS_BUILTIN_KIND(InvalidType, "<unknown>")
  41. // -----------------------------------------------------------------------------
  42. // TODO: Below types are all placeholders. While the above may last, the below
  43. // are expected to need to change in order to better reflect Carbon's design.
  44. // Keeping distinct placeholders can help find usages for later fixes.
  45. // -----------------------------------------------------------------------------
  46. // The type of bool literals and branch conditions, bool.
  47. CARBON_SEMANTICS_BUILTIN_KIND(BoolType, "bool")
  48. // The type of integer values and integer literals, currently always i32.
  49. CARBON_SEMANTICS_BUILTIN_KIND(IntegerType, "i32")
  50. // The type of floating point values and real literals, currently always f64.
  51. CARBON_SEMANTICS_BUILTIN_KIND(FloatingPointType, "f64")
  52. // The type of string values and String literals.
  53. CARBON_SEMANTICS_BUILTIN_KIND(StringType, "String")
  54. // The canonical empty tuple type.
  55. CARBON_SEMANTICS_BUILTIN_KIND(EmptyTupleType, "() as Type")
  56. // Keep invalid last, so that we can use values as array indices without needing
  57. // an invalid entry.
  58. CARBON_SEMANTICS_BUILTIN_KIND_NAME(Invalid)
  59. #undef CARBON_SEMANTICS_BUILTIN_KIND_NAME
  60. #undef CARBON_SEMANTICS_BUILTIN_KIND