diagnostic_kind.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_DIAGNOSTIC_KIND_H_
  5. #define CARBON_TOOLCHAIN_DIAGNOSTICS_DIAGNOSTIC_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. // NOLINTNEXTLINE(performance-enum-size)
  12. CARBON_DEFINE_RAW_ENUM_CLASS(Kind, uint16_t) {
  13. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
  14. #include "toolchain/diagnostics/diagnostic_kind.def"
  15. };
  16. // An enumeration of all diagnostics provided by the toolchain. Diagnostics must
  17. // be added to diagnostic_kind.def, and defined locally to where they're
  18. // used using the `DIAGNOSTIC` macro in diagnostic_emitter.h.
  19. //
  20. // Diagnostic definitions are decentralized because placing all diagnostic
  21. // definitions centrally is expected to create a compilation bottleneck
  22. // long-term, and we also see value to keeping diagnostic format strings close
  23. // to the consuming code.
  24. class Kind : public CARBON_ENUM_BASE(Kind) {
  25. public:
  26. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_ENUM_CONSTANT_DECL(Name)
  27. #include "toolchain/diagnostics/diagnostic_kind.def"
  28. };
  29. #define CARBON_DIAGNOSTIC_KIND(Name) CARBON_ENUM_CONSTANT_DEFINITION(Kind, Name)
  30. #include "toolchain/diagnostics/diagnostic_kind.def"
  31. // We expect Kind to fit into 2 bits.
  32. static_assert(sizeof(Kind) == 2, "Kind includes padding!");
  33. } // namespace Carbon::Diagnostics
  34. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_DIAGNOSTIC_KIND_H_