Skip to content

Commit

Permalink
Fix Clang warning -Wweak-vtables.
Browse files Browse the repository at this point in the history
  • Loading branch information
skvadrik committed Nov 13, 2024
1 parent a5e37dc commit efc527c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 38 deletions.
23 changes: 5 additions & 18 deletions src/codegen/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 4 additions & 0 deletions src/codegen/pass1_analyze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace re2c {

namespace {

class GenBitmapChecks : public RenderCallback {
std::ostream& os;
const opt_t* opts;
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 24 additions & 20 deletions src/codegen/pass2_generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/codegen/pass4_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace re2c {

namespace {

static void render(RenderContext& rctx, const Code* code);

static bool oneline_stmt_list(const CodeList* list) {
Expand Down Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions src/options/opt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "<undefined code:" #name ">"; \
Expand Down Expand Up @@ -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

0 comments on commit efc527c

Please sign in to comment.