semantics_builtin_kind.def 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // Note that this is an X-macro header.
  6. //
  7. // It does not use `#include` guards, and instead is designed to be `#include`ed
  8. // after the x-macro is defined in order for its inclusion to expand to the
  9. // desired output.
  10. //
  11. // x-macros come in two forms:
  12. // CARBON_SEMANTICS_BUILTIN_KIND_NAME(Name)
  13. // Used as a fallback if other macros are missing.
  14. // CARBON_SEMANTICS_BUILTIN_KIND(Name, Type)
  15. // Defines a builtin kind with the associated type, which must also be
  16. // builtin.
  17. //
  18. // Note that Invalid is provided with CARBON_SEMANTICS_BUILTIN_KIND_NAME but not
  19. // CARBON_SEMANTICS_BUILTIN_KIND.
  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)
  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)
  42. // The type of integers and integer literals, currently always i32. Long-term
  43. // we may not want it this way, but for now this is the approach.
  44. CARBON_SEMANTICS_BUILTIN_KIND(IntegerType, TypeType)
  45. // The type of reals and real literals, currently always f64. Long-term
  46. // we may not want it this way, but for now this is the approach.
  47. CARBON_SEMANTICS_BUILTIN_KIND(RealType, TypeType)
  48. // Keep invalid last, so that we can use values as array indices without needing
  49. // an invalid entry.
  50. CARBON_SEMANTICS_BUILTIN_KIND_NAME(Invalid)
  51. #undef CARBON_SEMANTICS_BUILTIN_KIND_NAME
  52. #undef CARBON_SEMANTICS_BUILTIN_KIND