Skip to content

Commit f6b9826

Browse files
authored
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).
1 parent 3d77c44 commit f6b9826

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

toolchain/parse/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ cc_library(
121121
srcs = ["dump.cpp"],
122122
hdrs = ["dump.h"],
123123
deps = [
124+
":context",
124125
":tree",
125126
"//common:ostream",
126127
"//common:raw_string_ostream",

toolchain/parse/dump.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "common/raw_string_ostream.h"
1212
#include "toolchain/lex/dump.h"
13+
#include "toolchain/parse/context.h"
1314

1415
namespace Carbon::Parse {
1516

@@ -33,6 +34,16 @@ LLVM_DUMP_METHOD auto Dump(const Tree& tree, NodeId node_id) -> std::string {
3334
return out.TakeStr();
3435
}
3536

37+
static LLVM_DUMP_METHOD auto Dump(const Context& context, Lex::TokenIndex token)
38+
-> std::string {
39+
return Dump(context.tree(), token);
40+
}
41+
42+
static LLVM_DUMP_METHOD auto Dump(const Context& context, NodeId node_id)
43+
-> std::string {
44+
return Dump(context.tree(), node_id);
45+
}
46+
3647
} // namespace Carbon::Parse
3748

3849
#endif // NDEBUG

0 commit comments

Comments
 (0)