Skip to content

Commit

Permalink
count visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Jul 22, 2024
1 parent 80133af commit d5f34d1
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions source/graphql/countvisitor.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module graphql.countvisitor;

import std.traits : Unqual, Parameters;
import std.conv : to;
import std.stdio;
import std.string : indexOf;
import graphql.ast;
import graphql.visitor;
import graphql.tokenmodule;

class CountVisitor : ConstVisitor {
alias accept = ConstVisitor.accept;
alias enter = ConstVisitor.enter;
alias exit = ConstVisitor.exit;

mixin(genCountTables());

this() {
}
}

string genCountTables() {
string ret;
string[] all;
static foreach(it; __traits(getOverloads, Visitor, "accept")) {{
alias Params = Parameters!(it);
enum pName = Params[0].stringof;
static if(pName.indexOf("const(") == -1) {
all ~= pName;
ret ~= "\tlong " ~ Params[0].stringof ~ "Counter;\n";
ret ~= "\tlong " ~ Params[0].stringof ~ "CounterEnter;\n";
ret ~= "\tlong " ~ Params[0].stringof ~ "CounterExit;\n";
}
}}

ret ~= `
string countsToString() {
string ret;
`;
foreach(it; all) {
ret ~= "\t\tret ~= \"" ~ it ~ "Counter = \" ~ to!string(" ~ it
~ "Counter)" ~ " ~ \"\\n\";\n";
ret ~= "\t\tret ~= \"" ~ it ~ "CounterEnter = \" ~ to!string(" ~ it
~ "CounterEnter)" ~ " ~ \"\\n\";\n";
ret ~= "\t\tret ~= \"" ~ it ~ "CounterExit = \" ~ to!string(" ~ it
~ "CounterExit)" ~ " ~ \"\\n\";\n";
}
ret ~= `
return ret;
}
`;
return ret;
}

unittest {
auto c = new ConstVisitor();
}

0 comments on commit d5f34d1

Please sign in to comment.