kind.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #ifndef CARBON_TOOLCHAIN_DIAGNOSTICS_KIND_H_
  5. #define CARBON_TOOLCHAIN_DIAGNOSTICS_KIND_H_
  6. #include <cstdint>
  7. #include "common/enum_base.h"
  8. namespace Carbon::Diagnostics {
  9. // Although this currently fits into int8_t, it shouldn't be expected to
  10. // long-term.
  11. CARBON_DEFINE_RAW_ENUM_CLASS(Kind, uint16_t) {
  12. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
  13. #include "toolchain/diagnostics/kind.def"
  14. };
  15. // An enumeration of all diagnostics provided by the toolchain. Diagnostics must
  16. // be added to kind.def, and defined locally to where they're used using the
  17. // `DIAGNOSTIC` macro in emitter.h.
  18. //
  19. // Diagnostic definitions are decentralized because placing all diagnostic
  20. // definitions centrally is expected to create a compilation bottleneck
  21. // long-term, and we also see value to keeping diagnostic format strings close
  22. // to the consuming code.
  23. class Kind : public CARBON_ENUM_BASE(Kind) {
  24. public:
  25. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_ENUM_CONSTANT_DECL(Name)
  26. #include "toolchain/diagnostics/kind.def"
  27. };
  28. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_ENUM_CONSTANT_DEFINITION(Kind, Name)
  29. #include "toolchain/diagnostics/kind.def"
  30. // We expect Kind to fit into 2 bits.
  31. static_assert(sizeof(Kind) == 2, "Kind includes padding!");
  32. } // namespace Carbon::Diagnostics
  33. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_KIND_H_