diagnostic_helpers.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_CHECK_DIAGNOSTIC_HELPERS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_DIAGNOSTIC_HELPERS_H_
  6. #include "llvm/ADT/APSInt.h"
  7. #include "toolchain/parse/node_ids.h"
  8. #include "toolchain/parse/tree_node_diagnostic_converter.h"
  9. #include "toolchain/sem_ir/ids.h"
  10. namespace Carbon::Check {
  11. // Diagnostic locations produced by checking may be either a parse node
  12. // directly, or an inst ID which is later translated to a parse node.
  13. struct SemIRLocation {
  14. // NOLINTNEXTLINE(google-explicit-constructor)
  15. SemIRLocation(SemIR::InstId inst_id) : inst_id(inst_id), is_inst_id(true) {}
  16. // NOLINTNEXTLINE(google-explicit-constructor)
  17. SemIRLocation(Parse::NodeLocation node_location)
  18. : node_location(node_location), is_inst_id(false) {}
  19. // NOLINTNEXTLINE(google-explicit-constructor)
  20. SemIRLocation(Parse::NodeId node_id)
  21. : SemIRLocation(Parse::NodeLocation(node_id)) {}
  22. union {
  23. SemIR::InstId inst_id;
  24. Parse::NodeLocation node_location;
  25. };
  26. bool is_inst_id;
  27. };
  28. // An integer value together with its type. The type is used to determine how to
  29. // format the value in diagnostics.
  30. struct TypedInt {
  31. using DiagnosticType = DiagnosticTypeInfo<llvm::APSInt>;
  32. SemIR::TypeId type;
  33. llvm::APInt value;
  34. };
  35. } // namespace Carbon::Check
  36. #endif // CARBON_TOOLCHAIN_CHECK_DIAGNOSTIC_HELPERS_H_