Skip to content

Commit

Permalink
Rename OutptuCallback to RenderCallback.
Browse files Browse the repository at this point in the history
All syntax file base codegen has been moved to rendering phase.
  • Loading branch information
skvadrik committed Dec 4, 2023
1 parent 63e5eb6 commit 2e695cb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
46 changes: 23 additions & 23 deletions src/codegen/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ struct RenderContext {
FORBID_COPY(RenderContext);
};

class RenderCallback {
public:
virtual void render_var(const char* /*var*/) {
UNREACHABLE();
}
virtual size_t get_list_size(const char* /*var*/) const {
UNREACHABLE();
return 0;
}
virtual void start_list(const char* /*var*/, size_t /*lbound*/, size_t /*rbound*/) {
UNREACHABLE();
}
virtual bool next_in_list(const char* /*var*/) {
UNREACHABLE();
return false;
}
virtual bool eval_cond(const char* /*cond*/) {
UNREACHABLE();
return false;
}
virtual ~RenderCallback() = default;
};

struct StartCond {
std::string name;
uint32_t number;
Expand Down Expand Up @@ -140,29 +163,6 @@ struct Output {
FORBID_COPY(Output);
};

class OutputCallback {
public:
virtual void render_var(const char* /*var*/) {
UNREACHABLE();
}
virtual size_t get_list_size(const char* /*var*/) const {
UNREACHABLE();
return 0;
}
virtual void start_list(const char* /*var*/, size_t /*lbound*/, size_t /*rbound*/) {
UNREACHABLE();
}
virtual bool next_in_list(const char* /*var*/) {
UNREACHABLE();
return false;
}
virtual bool eval_cond(const char* /*cond*/) {
UNREACHABLE();
return false;
}
virtual ~OutputCallback() = default;
};

void init_go(CodeGo* go);
bool endstate(const State* s);
bool consume(const State* s);
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/pass2_generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ LOCAL_NODISCARD(Ret expand_tags_directive(Output& output, Code* code)) {
return Ret::OK;
}

class GenEnum : public OutputCallback {
class GenEnum : public RenderCallback {
OutAllocator& alc;
Scratchbuf& buf;
const opt_t* opts;
Expand Down
18 changes: 9 additions & 9 deletions src/codegen/pass4_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void render_block(RenderContext& rctx, const CodeBlock* code) {
}
}

class RenderVar : public OutputCallback {
class RenderVar : public RenderCallback {
RenderContext& rctx;
const CodeVar* code;

Expand Down Expand Up @@ -148,7 +148,7 @@ class RenderVar : public OutputCallback {
FORBID_COPY(RenderVar);
};

class RenderIfThenElse : public OutputCallback {
class RenderIfThenElse : public RenderCallback {
RenderContext& rctx;
const CodeIfTE* code;
const Code* curr_stmt;
Expand Down Expand Up @@ -257,7 +257,7 @@ static void render_number(RenderContext& rctx, int64_t num, VarType type) {
}
}

class RenderSwitchCaseDefault : public OutputCallback {
class RenderSwitchCaseDefault : public RenderCallback {
RenderContext& rctx;

public:
Expand All @@ -268,7 +268,7 @@ class RenderSwitchCaseDefault : public OutputCallback {
}
};

class RenderSwitchCaseRange : public OutputCallback {
class RenderSwitchCaseRange : public RenderCallback {
RenderContext& rctx;
const CodeCase* code;
size_t curr_range;
Expand Down Expand Up @@ -349,7 +349,7 @@ class RenderSwitchCaseRange : public OutputCallback {
FORBID_COPY(RenderSwitchCaseRange);
};

class RenderSwitchCaseBlock : public OutputCallback {
class RenderSwitchCaseBlock : public RenderCallback {
RenderContext& rctx;
const CodeCase* code;
const Code* curr_stmt;
Expand Down Expand Up @@ -437,7 +437,7 @@ class RenderSwitchCaseBlock : public OutputCallback {
FORBID_COPY(RenderSwitchCaseBlock);
};

class RenderSwitch : public OutputCallback {
class RenderSwitch : public RenderCallback {
RenderContext& rctx;
const CodeSwitch* code;
const CodeCase* curr_case;
Expand Down Expand Up @@ -497,7 +497,7 @@ class RenderSwitch : public OutputCallback {
FORBID_COPY(RenderSwitch);
};

class RenderLoop : public OutputCallback {
class RenderLoop : public RenderCallback {
RenderContext& rctx;
const CodeList* code;
const Code* curr_stmt;
Expand Down Expand Up @@ -793,7 +793,7 @@ static void render_label(RenderContext& rctx, const CodeLabel& label) {
}
}

class RenderArray : public OutputCallback {
class RenderArray : public RenderCallback {
RenderContext& rctx;
const CodeArray* code;
const size_t ncols;
Expand Down Expand Up @@ -879,7 +879,7 @@ class RenderArray : public OutputCallback {
FORBID_COPY(RenderArray);
};

class RenderEnum : public OutputCallback {
class RenderEnum : public RenderCallback {
RenderContext& rctx;
const CodeEnum* code;
size_t curr_elem;
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/syntax.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void Stx::push_list_on_stack(const StxCode* x) {
stack_code.push_back({x, 0});
}

bool Stx::eval_cond(const char* cond, const opt_t* opts, OutputCallback& callback) const {
bool Stx::eval_cond(const char* cond, const opt_t* opts, RenderCallback& callback) const {
auto i = allowed_conds.find(cond);
if (i != allowed_conds.end()) {
return i->second(opts);
Expand All @@ -283,7 +283,7 @@ static inline bool eval_list_bounds(size_t size, int32_t& lbound, int32_t& rboun
}

void Stx::gen_code(
std::ostream& os, const opt_t* opts, const char* name, OutputCallback& callback) {
std::ostream& os, const opt_t* opts, const char* name, RenderCallback& callback) {
DCHECK(confs.find(name) != confs.end());
const StxConf* conf = confs[name];
CHECK(conf->type == StxConfType::CODE);
Expand Down Expand Up @@ -331,7 +331,7 @@ void Stx::gen_code(
}

void Stx::gen_str(std::ostream& os, const opt_t* opts, const char* name) {
OutputCallback dummy;
RenderCallback dummy;
gen_code(os, opts, name, dummy);
}

Expand Down
6 changes: 3 additions & 3 deletions src/codegen/syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace re2c {

class OutputCallback;
class RenderCallback;
struct StxCode;

struct StxCodeCond {
Expand Down Expand Up @@ -127,7 +127,7 @@ class Stx {
Ret check_var(const char* conf, const char* var) const;

void push_list_on_stack(const StxCode* x);
bool eval_cond(const char* cond, const opt_t* opts, OutputCallback& callback) const;
bool eval_cond(const char* cond, const opt_t* opts, RenderCallback& callback) const;

bool have_conf(const char* name) const;

Expand Down Expand Up @@ -160,7 +160,7 @@ class Stx {
void cache_conf_tests();

// functions that generate code for a given syntax configuration
void gen_code(std::ostream& os, const opt_t* opts, const char* name, OutputCallback& callback);
void gen_code(std::ostream& os, const opt_t* opts, const char* name, RenderCallback& callback);
void gen_str(std::ostream& os, const opt_t* opts, const char* name);
};

Expand Down

0 comments on commit 2e695cb

Please sign in to comment.