Skip to content

Commit ac98abc

Browse files
committed
Improvements and fixes
1 parent ed5e37b commit ac98abc

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Fuzzer {
4646
glrParse(clang::pseudo::ParseParams{ParseableStream, Arena, GSS},
4747
*Lang.G.findNonterminal("translation-unit"), Lang);
4848
if (Print)
49-
llvm::outs() << Root.dumpRecursive(Lang.G, std::nullopt);
49+
llvm::outs() << Root.dumpRecursive(Lang.G);
5050
}
5151
};
5252

clang-tools-extra/pseudo/include/clang-pseudo/Forest.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ class alignas(class ForestNode *) ForestNode {
114114
// Iteration over all nodes in the forest, including this.
115115
llvm::iterator_range<RecursiveIterator> descendants() const;
116116

117-
std::string
118-
dump(const Grammar &,
119-
std::optional<std::reference_wrapper<const TokenStream>>) const;
117+
// Dump forest node to text. If Code is std::nullopt, terminals will be
118+
// displayed as token indexes.
119+
std::string dump(const Grammar &,
120+
std::optional<std::reference_wrapper<const TokenStream>>
121+
Code = std::nullopt) const;
122+
// Dump forest node recursively to text. If Code is std::nullopt, terminals
123+
// will be displayed as token indexes.
120124
std::string
121125
dumpRecursive(const Grammar &,
122-
std::optional<std::reference_wrapper<const TokenStream>>,
126+
std::optional<std::reference_wrapper<const TokenStream>> Code =
127+
std::nullopt,
123128
bool Abbreviated = false) const;
124129

125130
private:

clang-tools-extra/pseudo/lib/GLR.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ class GLRReduce {
527527
SequenceNodes.size() == 1
528528
? SequenceNodes.front()
529529
: &Params.Forest.createAmbiguous(F.Symbol, SequenceNodes);
530-
LLVM_DEBUG(llvm::dbgs()
531-
<< " --> " << Parsed->dump(Lang.G, std::nullopt) << "\n");
530+
LLVM_DEBUG(llvm::dbgs() << " --> " << Parsed->dump(Lang.G) << "\n");
532531

533532
// Bases for this family, deduplicate them, and group by the goTo State.
534533
sortAndUnique(FamilyBases);

clang-tools-extra/pseudo/tool/ClangPseudo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static opt<bool> PrintStatistics("print-statistics", desc("Print GLR parser stat
5353
static opt<bool> PrintForest("print-forest", desc("Print parse forest"));
5454
static opt<bool>
5555
PrintTerminalTokens("print-terminal-tokens",
56-
desc("Print terminal tokens in parse forest"));
56+
desc("Print terminal tokens in parse forest"));
5757
static opt<bool> ForestAbbrev("forest-abbrev", desc("Abbreviate parse forest"),
5858
init(true));
5959
static opt<std::string> HTMLForest("html-forest",

clang-tools-extra/pseudo/unittests/ForestTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ TEST_F(ForestTest, DumpBasic) {
7373
const auto *Add =
7474
&Arena.createSequence(symbol("add-expression"), ruleFor("add-expression"),
7575
{Left, &T[1], Right});
76-
EXPECT_EQ(Add->dumpRecursive(G, true),
76+
EXPECT_EQ(Add->dumpRecursive(G, std::nullopt, true),
7777
"[ 0, end) add-expression := id-expression + id-expression\n"
7878
"[ 0, 1) ├─id-expression~IDENTIFIER := tok[0]\n"
7979
"[ 1, 2) ├─+ := tok[1]\n"
8080
"[ 2, end) └─id-expression~IDENTIFIER := tok[2]\n");
81-
EXPECT_EQ(Add->dumpRecursive(G, false),
81+
EXPECT_EQ(Add->dumpRecursive(G, std::nullopt, false),
8282
"[ 0, end) add-expression := id-expression + id-expression\n"
8383
"[ 0, 1) ├─id-expression := IDENTIFIER\n"
8484
"[ 0, 1) │ └─IDENTIFIER := tok[0]\n"
@@ -144,7 +144,7 @@ TEST_F(ForestTest, DumpAbbreviatedShared) {
144144

145145
// We must not abbreviate away shared nodes: if we show A~* there's no way to
146146
// show that the intermediate B node is shared between A1 and A2.
147-
EXPECT_EQ(A->dumpRecursive(G, /*Abbreviate=*/true),
147+
EXPECT_EQ(A->dumpRecursive(G, std::nullopt, /*Abbreviate=*/true),
148148
"[ 0, end) A := <ambiguous>\n"
149149
"[ 0, end) ├─A~B := * #1\n"
150150
"[ 0, end) │ └─* := tok[0]\n"

0 commit comments

Comments
 (0)