summaryrefslogtreecommitdiff
path: root/src/options
diff options
context:
space:
mode:
authorGereon Kremer <gereon.kremer@cs.rwth-aachen.de>2021-04-29 18:20:36 +0200
committerGitHub <noreply@github.com>2021-04-29 16:20:36 +0000
commit13499235189b644fc194680afd5b37378d794c09 (patch)
treebdff5c91c648d882eda6a547a05a6774ceac6758 /src/options
parent3a1b36b7471cb3c9e26f3f4cbdb34ca42ba42d80 (diff)
Simplify generated code for getOption() and setOption() (#6462)
This PR simplifies the generated code for Options::getOption() and Options::setOption(). It now uses less string streams, less temporary vectors and the new options[...] syntax (instead of options::...().
Diffstat (limited to 'src/options')
-rw-r--r--src/options/mkoptions.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/options/mkoptions.py b/src/options/mkoptions.py
index 13df7b8bd..e2c138490 100644
--- a/src/options/mkoptions.py
+++ b/src/options/mkoptions.py
@@ -746,15 +746,17 @@ def codegen_all_modules(modules, dst_dir, tpl_options, tpl_options_holder):
'if ({}) {{'.format(cond))
if option.type == 'bool':
getoption_handlers.append(
- 'return options::{}() ? "true" : "false";'.format(
- option.name))
+ 'return (*this)[options::{}] ? "true" : "false";'.format(option.name))
+ elif option.type == 'std::string':
+ getoption_handlers.append(
+ 'return (*this)[options::{}];'.format(option.name))
+ elif is_numeric_cpp_type(option.type):
+ getoption_handlers.append(
+ 'return std::to_string((*this)[options::{}]);'.format(option.name))
else:
getoption_handlers.append('std::stringstream ss;')
- if is_numeric_cpp_type(option.type):
- getoption_handlers.append(
- 'ss << std::fixed << std::setprecision(8);')
- getoption_handlers.append('ss << options::{}();'.format(
- option.name))
+ getoption_handlers.append(
+ 'ss << (*this)[options::{}];'.format(option.name))
getoption_handlers.append('return ss.str();')
getoption_handlers.append('}')
@@ -788,21 +790,14 @@ def codegen_all_modules(modules, dst_dir, tpl_options, tpl_options_holder):
options_smt.append('"{}",'.format(optname))
if option.type == 'bool':
- s = '{ std::vector<std::string> v; '
- s += 'v.push_back("{}"); '.format(optname)
- s += 'v.push_back(std::string('
- s += 'd_holder->{}'.format(option.name)
- s += ' ? "true" : "false")); '
- s += 'opts.push_back(v); }'
+ s = 'opts.push_back({{"{}", d_holder->{} ? "true" : "false"}});'.format(
+ optname, option.name)
+ elif is_numeric_cpp_type(option.type):
+ s = 'opts.push_back({{"{}", std::to_string(d_holder->{})}});'.format(
+ optname, option.name)
else:
- s = '{ std::stringstream ss; '
- if is_numeric_cpp_type(option.type):
- s += 'ss << std::fixed << std::setprecision(8); '
- s += 'ss << d_holder->{}; '.format(option.name)
- s += 'std::vector<std::string> v; '
- s += 'v.push_back("{}"); '.format(optname)
- s += 'v.push_back(ss.str()); '
- s += 'opts.push_back(v); }'
+ s = '{{ std::stringstream ss; ss << d_holder->{}; opts.push_back({{"{}", ss.str()}}); }}'.format(
+ option.name, optname)
options_getoptions.append(s)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback