From efc527c2ac24418bf7b62a078833a6028b4e2392 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 13 Nov 2024 22:40:31 +0000 Subject: [PATCH] Fix Clang warning -Wweak-vtables. --- src/codegen/output.h | 23 ++++-------------- src/codegen/pass1_analyze.cc | 4 ++++ src/codegen/pass2_generate.cc | 44 +++++++++++++++++++---------------- src/codegen/pass4_render.cc | 4 ++++ src/options/opt.cc | 27 +++++++++++++++++++++ 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/src/codegen/output.h b/src/codegen/output.h index 4ab7de867..4651f114b 100644 --- a/src/codegen/output.h +++ b/src/codegen/output.h @@ -68,24 +68,11 @@ struct RenderContext { class RenderCallback { public: - virtual void render_var(StxVarId /*var*/) { - UNREACHABLE(); - } - virtual size_t get_list_size(StxVarId /*var*/) const { - UNREACHABLE(); - return 0; - } - virtual void start_list(StxVarId /*var*/, size_t /*lbound*/, size_t /*rbound*/) { - UNREACHABLE(); - } - virtual bool next_in_list(StxVarId /*var*/) { - UNREACHABLE(); - return false; - } - virtual bool eval_cond(StxLOpt /*opt*/) { - UNREACHABLE(); - return false; - } + virtual void render_var(StxVarId var); + virtual size_t get_list_size(StxVarId var) const; + virtual void start_list(StxVarId var, size_t lbound, size_t rbound); + virtual bool next_in_list(StxVarId var); + virtual bool eval_cond(StxLOpt opt); virtual ~RenderCallback() = default; }; diff --git a/src/codegen/pass1_analyze.cc b/src/codegen/pass1_analyze.cc index 341042dc1..e614abe31 100644 --- a/src/codegen/pass1_analyze.cc +++ b/src/codegen/pass1_analyze.cc @@ -12,6 +12,8 @@ namespace re2c { +namespace { + class GenBitmapChecks : public RenderCallback { std::ostream& os; const opt_t* opts; @@ -50,6 +52,8 @@ class GenBitmapChecks : public RenderCallback { FORBID_COPY(GenBitmapChecks); }; +} // anonymous namespace + // All spans in b1 that lead to s1 are pairwise equal to that in b2 leading to s2 static bool matches( const opt_t* opts, const CodeGo* go1, const State* s1, const CodeGo* go2, const State* s2) { diff --git a/src/codegen/pass2_generate.cc b/src/codegen/pass2_generate.cc index aaeff2af3..2f5e52ecd 100644 --- a/src/codegen/pass2_generate.cc +++ b/src/codegen/pass2_generate.cc @@ -24,6 +24,8 @@ namespace re2c { static CodeList* gen_goswif( Output& output, const Adfa& dfa, const CodeGoSwIf* go, const State* from); +namespace { + class GenArrayElem : public RenderCallback { std::ostream& os; const char* array; @@ -155,6 +157,28 @@ class GenLessThan : public RenderCallback { FORBID_COPY(GenLessThan); }; +class GenEnumElem : public RenderCallback { + std::ostream& os; + const std::string& type; + const std::string& name; + + public: + GenEnumElem(std::ostream& os, const std::string& type, const std::string& name) + : os(os), type(type), name(name) {} + + void render_var(StxVarId var) override { + switch (var) { + case StxVarId::TYPE: os << type; break; + case StxVarId::NAME: os << name; break; + default: UNREACHABLE(); break; + } + } + + FORBID_COPY(GenEnumElem); +}; + +} // anonymous namespace + bool endstate(const State* s) { // An 'end' state is a state which has no outgoing transitions on symbols. Usually 'end' states // are final states (not all final states are 'end' states), but sometimes it be initial @@ -934,26 +958,6 @@ static void emit_accept( append(stmts, code_switch(alc, var, cases)); } -class GenEnumElem : public RenderCallback { - std::ostream& os; - const std::string& type; - const std::string& name; - - public: - GenEnumElem(std::ostream& os, const std::string& type, const std::string& name) - : os(os), type(type), name(name) {} - - void render_var(StxVarId var) override { - switch (var) { - case StxVarId::TYPE: os << type; break; - case StxVarId::NAME: os << name; break; - default: UNREACHABLE(); break; - } - } - - FORBID_COPY(GenEnumElem); -}; - static const char* gen_cond_enum_elem(Scratchbuf& buf, const opt_t* opts, const std::string& name) { const std::string& cond = opts->cond_enum_prefix + name; GenEnumElem callback(buf.stream(), opts->api_cond_type, cond); diff --git a/src/codegen/pass4_render.cc b/src/codegen/pass4_render.cc index c5a66558b..69ab67855 100644 --- a/src/codegen/pass4_render.cc +++ b/src/codegen/pass4_render.cc @@ -10,6 +10,8 @@ namespace re2c { +namespace { + static void render(RenderContext& rctx, const Code* code); static bool oneline_stmt_list(const CodeList* list) { @@ -1705,6 +1707,8 @@ LOCAL_NODISCARD(Ret codegen_render_blocks( return Ret::OK; } +} // anonymous namespace + Ret codegen_render(Output& output) { const opt_t* opts = output.total_opts; // global options diff --git a/src/options/opt.cc b/src/options/opt.cc index 10a56beb1..7f927693c 100644 --- a/src/options/opt.cc +++ b/src/options/opt.cc @@ -877,6 +877,8 @@ void opt_t::render_code_##name(std::ostream& os) const { \ RE2C_CODE_TEMPLATES #undef CODE_TEMPLATE +namespace { + class GenOpt : public RenderCallback { std::ostringstream &os; const opt_t* opts; @@ -910,6 +912,8 @@ class GenOpt : public RenderCallback { FORBID_COPY(GenOpt); }; +} // anonymous namespace + #define MUTCODE(name) \ std::string opt_t::gen_##name(const StxCodes* code) const { \ if (code == nullptr) return ""; \ @@ -983,4 +987,27 @@ bool is_undefined(const StxCodes* code) { && code->head->type == StxCodeType::UD; } +void RenderCallback::render_var(StxVarId /*var*/) { + UNREACHABLE(); +} + +size_t RenderCallback::get_list_size(StxVarId /*var*/) const { + UNREACHABLE(); + return 0; +} + +void RenderCallback::start_list(StxVarId /*var*/, size_t /*lbound*/, size_t /*rbound*/) { + UNREACHABLE(); +} + +bool RenderCallback::next_in_list(StxVarId /*var*/) { + UNREACHABLE(); + return false; +} + +bool RenderCallback::eval_cond(StxLOpt /*opt*/) { + UNREACHABLE(); + return false; +} + } // namespace re2c