file_diagnostics.h 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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_FILE_DIAGNOSTICS_H_
  5. #define CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_
  6. #include "toolchain/diagnostics/emitter.h"
  7. namespace Carbon::Diagnostics {
  8. // We frequently want a `Emitter` that directly uses a filename. Note
  9. // that an empty string can be used for a diagnostic that has no particular
  10. // location.
  11. //
  12. // Note this provides no way to set a line or column on diagnostics. More
  13. // specific emitters must be used for that.
  14. class FileEmitter : public Emitter<llvm::StringRef> {
  15. public:
  16. using Emitter::Emitter;
  17. protected:
  18. // Converts a filename directly to the diagnostic location.
  19. auto ConvertLoc(llvm::StringRef filename, ContextFnT /*context_fn*/) const
  20. -> ConvertedLoc override {
  21. return {.loc = {.filename = filename}, .last_byte_offset = -1};
  22. }
  23. };
  24. } // namespace Carbon::Diagnostics
  25. #endif // CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_