diagnostic_kind.h 1.6 KB

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