semantics_builtin_kind.def 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, Type, Label)
  15. // Defines a builtin kind with the associated type, which must also be
  16. // builtin.
  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, TypeType, "Type")
  38. // Used when a SemanticNode has an invalid type, which should then be ignored
  39. // for future type checking.
  40. // This has a deliberately self-referential type.
  41. CARBON_SEMANTICS_BUILTIN_KIND(InvalidType, InvalidType, "<unknown>")
  42. // -----------------------------------------------------------------------------
  43. // TODO: Below types are all placeholders. While the above may last, the below
  44. // are expected to need to change in order to better reflect Carbon's design.
  45. // Keeping distinct placeholders can help find usages for later fixes.
  46. // -----------------------------------------------------------------------------
  47. // The type of integer values and integer literals, currently always i32.
  48. CARBON_SEMANTICS_BUILTIN_KIND(IntegerType, TypeType, "i32")
  49. // The type of floating point values and real literals, currently always f64.
  50. CARBON_SEMANTICS_BUILTIN_KIND(FloatingPointType, TypeType, "f64")
  51. // The type of string values and String literals.
  52. CARBON_SEMANTICS_BUILTIN_KIND(StringType, TypeType, "String")
  53. // The canonical empty tuple type.
  54. CARBON_SEMANTICS_BUILTIN_KIND(EmptyTupleType, TypeType, "() as Type")
  55. // The canonical empty tuple.
  56. CARBON_SEMANTICS_BUILTIN_KIND(EmptyTuple, EmptyTupleType, "()")
  57. // Keep invalid last, so that we can use values as array indices without needing
  58. // an invalid entry.
  59. CARBON_SEMANTICS_BUILTIN_KIND_NAME(Invalid)
  60. #undef CARBON_SEMANTICS_BUILTIN_KIND_NAME
  61. #undef CARBON_SEMANTICS_BUILTIN_KIND