diagnostic_kind.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 {
  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(DiagnosticKind, 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 DiagnosticKind : public CARBON_ENUM_BASE(DiagnosticKind) {
  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) \
  30. CARBON_ENUM_CONSTANT_DEFINITION(DiagnosticKind, Name)
  31. #include "toolchain/diagnostics/diagnostic_kind.def"
  32. // We expect DiagnosticKind to fit into 2 bits.
  33. static_assert(sizeof(DiagnosticKind) == 2, "DiagnosticKind includes padding!");
  34. } // namespace Carbon
  35. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_DIAGNOSTIC_KIND_H_