Skip to content

Commit

Permalink
Save boolean configuration value in a field.
Browse files Browse the repository at this point in the history
Previously it was recomputed from the numeric value every time. Although
the recomputation was trivial (comparing against zero), it made the code
more verbose and less readable.
  • Loading branch information
skvadrik committed Aug 11, 2024
1 parent 1290b74 commit c05bad2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
26 changes: 13 additions & 13 deletions bootstrap/src/parse/conf_lexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ size_t LexerState::maxfill_conf() { return 30; }

#define RET_CONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
SETOPT(conf, tmp_num != 0); \
SETOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

#define RET_STXCONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
SETCONOPT(conf, tmp_num != 0); \
SETCONOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

#define RET_CONF_FEAT(conf, name) do { \
CHECK_RET(lex_conf_bool(opts)); \
if (tmp_num != 0 && !opts.glob.supported_features_contains(name)) { \
if (tmp_bool && !opts.glob.supported_features_contains(name)) { \
RET_FAIL(error_at_cur("`%s` feature is not supported for this backend", name)); \
} \
SETOPT(conf, tmp_num != 0); \
SETOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

Expand All @@ -79,9 +79,9 @@ size_t LexerState::maxfill_conf() { return 30; }
#define RET_CONF_ENC(enc) do { \
CHECK_RET(lex_conf_bool(opts)); \
if (in_syntax_file) { \
opts.init_encoding(enc, tmp_num != 0); \
opts.init_encoding(enc, tmp_bool); \
} else { \
opts.set_encoding(enc, tmp_num != 0); \
opts.set_encoding(enc, tmp_bool); \
} \
return Ret::OK; \
} while(0)
Expand Down Expand Up @@ -1343,8 +1343,8 @@ Ret Input::lex_conf(Opt& opts) {
#line 165 "../src/parse/conf_lexer.re"
{
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures_posix, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_posix, tmp_bool);
SETOPT(captures_array, true);
return Ret::OK;
}
Expand Down Expand Up @@ -1689,7 +1689,7 @@ Ret Input::lex_conf(Opt& opts) {
#line 159 "../src/parse/conf_lexer.re"
{
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_array, true);
return Ret::OK;
}
Expand All @@ -1702,7 +1702,7 @@ Ret Input::lex_conf(Opt& opts) {
#line 172 "../src/parse/conf_lexer.re"
{
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_array, false);
return Ret::OK;
}
Expand Down Expand Up @@ -3906,8 +3906,8 @@ Ret Input::lex_conf(Opt& opts) {
#line 178 "../src/parse/conf_lexer.re"
{
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures_posix, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_posix, tmp_bool);
SETOPT(captures_array, false);
return Ret::OK;
}
Expand Down Expand Up @@ -11200,7 +11200,7 @@ Ret Input::lex_conf_token(CONF_STYPE* yylval, int& token, Opt& opts) {

#define SAVE_CONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
opts.set_##conf(tmp_num != 0); \
opts.set_##conf(tmp_bool); \
goto start; \
} while(0)

Expand Down
26 changes: 13 additions & 13 deletions src/parse/conf_lexer.re
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ namespace re2c {

#define RET_CONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
SETOPT(conf, tmp_num != 0); \
SETOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

#define RET_STXCONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
SETCONOPT(conf, tmp_num != 0); \
SETCONOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

#define RET_CONF_FEAT(conf, name) do { \
CHECK_RET(lex_conf_bool(opts)); \
if (tmp_num != 0 && !opts.glob.supported_features_contains(name)) { \
if (tmp_bool && !opts.glob.supported_features_contains(name)) { \
RET_FAIL(error_at_cur("`%s` feature is not supported for this backend", name)); \
} \
SETOPT(conf, tmp_num != 0); \
SETOPT(conf, tmp_bool); \
return Ret::OK; \
} while(0)

Expand All @@ -74,9 +74,9 @@ namespace re2c {
#define RET_CONF_ENC(enc) do { \
CHECK_RET(lex_conf_bool(opts)); \
if (in_syntax_file) { \
opts.init_encoding(enc, tmp_num != 0); \
opts.init_encoding(enc, tmp_bool); \
} else { \
opts.set_encoding(enc, tmp_num != 0); \
opts.set_encoding(enc, tmp_bool); \
} \
return Ret::OK; \
} while(0)
Expand Down Expand Up @@ -158,27 +158,27 @@ Ret Input::lex_conf(Opt& opts) {
}
"flags:"? "leftmost-"? "captures" {
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_array, true);
return Ret::OK;
}
"flags:"? "posix-captures" | "flags:P" {
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures_posix, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_posix, tmp_bool);
SETOPT(captures_array, true);
return Ret::OK;
}
"leftmost-"? "captvars" {
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_array, false);
return Ret::OK;
}
"posix-captvars" {
CHECK_RET(lex_conf_bool(opts));
SETOPT(captures, tmp_num != 0);
SETOPT(captures_posix, tmp_num != 0);
SETOPT(captures, tmp_bool);
SETOPT(captures_posix, tmp_bool);
SETOPT(captures_array, false);
return Ret::OK;
}
Expand Down Expand Up @@ -802,7 +802,7 @@ start:

#define SAVE_CONF_BOOL(conf) do { \
CHECK_RET(lex_conf_bool(opts)); \
opts.set_##conf(tmp_num != 0); \
opts.set_##conf(tmp_bool); \
goto start; \
} while(0)

Expand Down
3 changes: 3 additions & 0 deletions src/parse/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Input: private LexerState {
enum class ConfKind {NONE, STR, NUM, LIST, CODE} conf_kind;
std::string tmp_str;
int32_t tmp_num;
bool tmp_bool;
std::vector<std::string> tmp_list;
const StxCodes* tmp_code;

Expand Down Expand Up @@ -175,6 +176,7 @@ inline Input::Input(OutAllocator& alc, const conopt_t* o, Msg& m)
conf_kind(ConfKind::NONE),
tmp_str(),
tmp_num(),
tmp_bool(),
tmp_list(),
tmp_code(),
in_syntax_file(false) {}
Expand Down Expand Up @@ -220,6 +222,7 @@ inline const InputFile& Input::get_cinput() const {
inline void Input::save_conf_num(int32_t num) {
conf_kind = ConfKind::NUM;
tmp_num = num;
tmp_bool = num != 0;
}

inline void Input::save_conf_str(const char* str) {
Expand Down

0 comments on commit c05bad2

Please sign in to comment.