dump.cpp 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  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/parse/dump.h"
  6. #include "common/ostream.h"
  7. #include "toolchain/lex/dump.h"
  8. namespace Carbon::Parse {
  9. auto DumpNoNewline(const Tree& tree, NodeId node_id) -> void {
  10. if (!node_id.has_value()) {
  11. llvm::errs() << "NodeId(invalid)";
  12. return;
  13. }
  14. auto kind = tree.node_kind(node_id);
  15. auto token = tree.node_token(node_id);
  16. llvm::errs() << "NodeId(kind: " << kind << ", token: ";
  17. Lex::DumpNoNewline(tree.tokens(), token);
  18. llvm::errs() << ")";
  19. }
  20. LLVM_DUMP_METHOD auto Dump(const Tree& tree, Lex::TokenIndex token) -> void {
  21. Lex::Dump(tree.tokens(), token);
  22. }
  23. LLVM_DUMP_METHOD auto Dump(const Tree& tree, NodeId node_id) -> void {
  24. DumpNoNewline(tree, node_id);
  25. llvm::errs() << '\n';
  26. }
  27. } // namespace Carbon::Parse
  28. #endif // NDEBUG