From b49604997bfe4c330367e6e6132d98ab49cb92e7 Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 2 Jun 2022 22:31:52 -0400 Subject: [PATCH] Removed IsOpeType --- lint/peglint.cc | 10 +++++--- peglib.h | 67 ++----------------------------------------------- 2 files changed, 8 insertions(+), 69 deletions(-) diff --git a/lint/peglint.cc b/lint/peglint.cc index c638bae..4beb940 100644 --- a/lint/peglint.cc +++ b/lint/peglint.cc @@ -195,8 +195,9 @@ int main(int argc, const char **argv) { if (opt_profile) { parser.enable_trace( [&](auto &ope, auto, auto, auto &, auto &, auto &) { - if (peg::IsOpeType::check(ope)) { - auto &name = dynamic_cast(ope).name(); + auto holder = dynamic_cast(&ope); + if (holder) { + auto &name = holder->name(); if (stats_index.find(name) == stats_index.end()) { stats_index[name] = stats_index.size(); stats.push_back({name, 0, 0}); @@ -205,8 +206,9 @@ int main(int argc, const char **argv) { } }, [&](auto &ope, auto, auto, auto &, auto &, auto &, auto len) { - if (peg::IsOpeType::check(ope)) { - auto &name = dynamic_cast(ope).name(); + auto holder = dynamic_cast(&ope); + if (holder) { + auto &name = holder->name(); auto index = stats_index[name]; auto &stat = stats[index]; if (len != static_cast(-1)) { diff --git a/peglib.h b/peglib.h index ba6f740..345f629 100644 --- a/peglib.h +++ b/peglib.h @@ -1746,69 +1746,6 @@ struct Ope::Visitor { virtual void visit(Cut &) {} }; -template struct IsOpeType : public Ope::Visitor { - void visit(Sequence &) override { ret_ = std::is_same::value; } - void visit(PrioritizedChoice &) override { - ret_ = std::is_same::value; - } - void visit(Repetition &) override { - ret_ = std::is_same::value; - } - void visit(AndPredicate &) override { - ret_ = std::is_same::value; - } - void visit(NotPredicate &) override { - ret_ = std::is_same::value; - } - void visit(Dictionary &) override { - ret_ = std::is_same::value; - } - void visit(LiteralString &) override { - ret_ = std::is_same::value; - } - void visit(CharacterClass &) override { - ret_ = std::is_same::value; - } - void visit(Character &) override { ret_ = std::is_same::value; } - void visit(AnyCharacter &) override { - ret_ = std::is_same::value; - } - void visit(CaptureScope &) override { - ret_ = std::is_same::value; - } - void visit(Capture &) override { ret_ = std::is_same::value; } - void visit(TokenBoundary &) override { - ret_ = std::is_same::value; - } - void visit(Ignore &) override { ret_ = std::is_same::value; } - void visit(User &) override { ret_ = std::is_same::value; } - void visit(WeakHolder &) override { - ret_ = std::is_same::value; - } - void visit(Holder &) override { ret_ = std::is_same::value; } - void visit(Reference &) override { ret_ = std::is_same::value; } - void visit(Whitespace &) override { - ret_ = std::is_same::value; - } - void visit(BackReference &) override { - ret_ = std::is_same::value; - } - void visit(PrecedenceClimbing &) override { - ret_ = std::is_same::value; - } - void visit(Recovery &) override { ret_ = std::is_same::value; } - void visit(Cut &) override { ret_ = std::is_same::value; } - - static bool check(const Ope &ope) { - IsOpeType vis; - const_cast(ope).accept(vis); - return vis.ret_; - } - -private: - bool ret_ = false; -}; - struct TraceOpeName : public Ope::Visitor { void visit(Sequence &) override { name_ = "Sequence"; } void visit(PrioritizedChoice &) override { name_ = "PrioritizedChoice"; } @@ -2598,7 +2535,7 @@ inline void Context::trace_leave(const Ope &ope, const char *a_s, size_t n, inline bool Context::is_traceable(const Ope &ope) const { if (tracer_enter && tracer_leave) { if (ignore_trace_state) { return false; } - return !IsOpeType::check(ope); + return !dynamic_cast(&ope); } return false; } @@ -2695,7 +2632,7 @@ inline size_t Holder::parse_core(const char *s, size_t n, SemanticValues &vs, chldsv.sv_ = std::string_view(s, len); chldsv.name_ = outer_->name; - if (!IsOpeType::check(*ope_)) { + if (!dynamic_cast(ope_.get())) { chldsv.choice_count_ = 0; chldsv.choice_ = 0; }