dump.cpp 955 B

123456789101112131415161718192021222324252627282930313233343536
  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 NDEBUG
  5. #include "toolchain/lex/dump.h"
  6. #include "common/ostream.h"
  7. namespace Carbon::Lex {
  8. auto DumpNoNewline(const TokenizedBuffer& tokens, TokenIndex token) -> void {
  9. if (!token.has_value()) {
  10. llvm::errs() << "TokenIndex(<none>)";
  11. return;
  12. }
  13. auto kind = tokens.GetKind(token);
  14. auto line = tokens.GetLineNumber(token);
  15. auto col = tokens.GetColumnNumber(token);
  16. llvm::errs() << "TokenIndex(kind: " << kind << ", loc: ";
  17. llvm::errs().write_escaped(tokens.source().filename());
  18. llvm::errs() << ":" << line << ":" << col << ")";
  19. }
  20. LLVM_DUMP_METHOD auto Dump(const TokenizedBuffer& tokens, TokenIndex token)
  21. -> void {
  22. DumpNoNewline(tokens, token);
  23. llvm::errs() << '\n';
  24. }
  25. } // namespace Carbon::Lex
  26. #endif // NDEBUG