Pārlūkot izejas kodu

Allow dumping with a Parse::Context (#5936)

Don't make the debugging user have to get the `.tree()` off of the
context (which takes a bit of work to find).
Dana Jansens 8 mēneši atpakaļ
vecāks
revīzija
f6b98261e1
2 mainītis faili ar 12 papildinājumiem un 0 dzēšanām
  1. 1 0
      toolchain/parse/BUILD
  2. 11 0
      toolchain/parse/dump.cpp

+ 1 - 0
toolchain/parse/BUILD

@@ -121,6 +121,7 @@ cc_library(
     srcs = ["dump.cpp"],
     hdrs = ["dump.h"],
     deps = [
+        ":context",
         ":tree",
         "//common:ostream",
         "//common:raw_string_ostream",

+ 11 - 0
toolchain/parse/dump.cpp

@@ -10,6 +10,7 @@
 
 #include "common/raw_string_ostream.h"
 #include "toolchain/lex/dump.h"
+#include "toolchain/parse/context.h"
 
 namespace Carbon::Parse {
 
@@ -33,6 +34,16 @@ LLVM_DUMP_METHOD auto Dump(const Tree& tree, NodeId node_id) -> std::string {
   return out.TakeStr();
 }
 
+static LLVM_DUMP_METHOD auto Dump(const Context& context, Lex::TokenIndex token)
+    -> std::string {
+  return Dump(context.tree(), token);
+}
+
+static LLVM_DUMP_METHOD auto Dump(const Context& context, NodeId node_id)
+    -> std::string {
+  return Dump(context.tree(), node_id);
+}
+
 }  // namespace Carbon::Parse
 
 #endif  // NDEBUG