Skip to content

Commit

Permalink
split visitor into const and non-const parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schadek committed May 15, 2019
1 parent b005126 commit 7798353
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ class Darser {
void visit(Visitor vis) const {
vis.accept(this);
}
void visit(ConstVisitor vis) {
vis.accept(this);
}
void visit(ConstVisitor vis) const {
vis.accept(this);
}
`
);

Expand Down Expand Up @@ -442,18 +450,29 @@ class Darser {
if(options.safe) {
formatIndent(ltw, 0, "@safe:\n\n");
}
formatIndent(ltw, 0, "class Visitor {\n");

// Visitor
formatIndent(ltw, 0, "class Visitor : ConstVisitor {\n");
formatIndent(ltw, 1, "alias accept = ConstVisitor.accept;\n\n");
formatIndent(ltw, 1, "alias enter = ConstVisitor.enter;\n\n");
formatIndent(ltw, 1, "alias exit = ConstVisitor.exit;\n\n");
if(!customAstFilename.empty) {
formatIndent(ltw, 0, readText(customAstFilename));
}

foreach(rule; this.rules) {
genVis!false(ltw, rule);
genVis!true(ltw, rule);
}
formatIndent(ltw, 0, "}\n\n");

formatIndent(ltw, 0, "}\n");
// Const Visitor
formatIndent(ltw, 0, "class ConstVisitor {\n");
if(!customAstFilename.empty) {
formatIndent(ltw, 0, readText(customAstFilename));
}
foreach(rule; this.rules) {
genVis!true(ltw, rule);
}
formatIndent(ltw, 0, "}\n\n");
}

void genTreeVisitor(File.LockingTextWriter ltw) {
Expand All @@ -467,9 +486,9 @@ class Darser {
if(options.safe) {
formatIndent(ltw, 0, "@safe:\n\n");
}
formatIndent(ltw, 0, "class TreeVisitor : Visitor {\n");
formatIndent(ltw, 0, "class TreeVisitor : ConstVisitor {\n");
formatIndent(ltw, 1, "import std.stdio : write, writeln;\n\n");
formatIndent(ltw, 1, "alias accept = Visitor.accept;\n\n");
formatIndent(ltw, 1, "alias accept = ConstVisitor.accept;\n\n");
formatIndent(ltw, 1, "int depth;\n\n");
formatIndent(ltw, 1, `this(int d) {
this.depth = d;
Expand Down

0 comments on commit 7798353

Please sign in to comment.