diff options
Diffstat (limited to 'src/options/mkoptions.py')
-rw-r--r-- | src/options/mkoptions.py | 76 |
1 files changed, 23 insertions, 53 deletions
diff --git a/src/options/mkoptions.py b/src/options/mkoptions.py index 3022c5d4b..8a7dbf605 100644 --- a/src/options/mkoptions.py +++ b/src/options/mkoptions.py @@ -287,16 +287,13 @@ def generate_get_impl(modules): ret = '{{ std::stringstream s; s << options.{}.{}; return s.str(); }}'.format( module.id, option.name) res.append('if ({}) {}'.format(cond, ret)) - return '\n '.join(res) + return '\n '.join(res) def _set_handlers(option): """Render handler call for options::set().""" if option.handler: - if option.type == 'void': - return 'opts.handler().{}(name)'.format(option.handler) - else: - return 'opts.handler().{}(name, optionarg)'.format(option.handler) + return 'opts.handler().{}(name, optionarg)'.format(option.handler) elif option.mode: return 'stringTo{}(optionarg)'.format(option.type) return 'handlers::handleOption<{}>(name, optionarg)'.format(option.type) @@ -304,9 +301,6 @@ def _set_handlers(option): def _set_predicates(option): """Render predicate calls for options::set().""" - if option.type == 'void': - return [] - assert option.type != 'void' res = [] if option.minimum: res.append( @@ -317,20 +311,11 @@ def _set_predicates(option): 'opts.handler().checkMaximum(name, value, static_cast<{}>({}));' .format(option.type, option.maximum)) res += [ - 'opts.handler().{}(name, value);'.format(x) - for x in option.predicates + 'opts.handler().{}(name, value);'.format(x) for x in option.predicates ] return res -TPL_SET = ''' opts.{module}.{name} = {handler}; - opts.{module}.{name}WasSetByUser = true;''' -TPL_SET_PRED = ''' auto value = {handler}; - {predicates} - opts.{module}.{name} = value; - opts.{module}.{name}WasSetByUser = true;''' - - def generate_set_impl(modules): """Generates the implementation for options::set().""" res = [] @@ -338,31 +323,19 @@ def generate_set_impl(modules): if not option.long: continue cond = ' || '.join(['name == "{}"'.format(x) for x in option.names]) - predicates = _set_predicates(option) if res: - res.append(' }} else if ({}) {{'.format(cond)) + res.append('}} else if ({}) {{'.format(cond)) else: res.append('if ({}) {{'.format(cond)) - if option.name and not (option.handler and option.mode): - if predicates: - res.append( - TPL_SET_PRED.format(module=module.id, - name=option.name, - handler=_set_handlers(option), - predicates='\n '.join(predicates))) - else: - res.append( - TPL_SET.format(module=module.id, - name=option.name, - handler=_set_handlers(option))) - elif option.handler: - h = ' opts.handler().{handler}(name' - if option.type not in ['bool', 'void']: - h += ', optionarg' - h += ');' - res.append( - h.format(handler=option.handler, smtname=option.long_name)) - return '\n'.join(res) + res.append(' auto value = {};'.format(_set_handlers(option))) + for pred in _set_predicates(option): + res.append(' {}'.format(pred)) + if option.name: + res.append(' opts.{module}.{name} = value;'.format( + module=module.id, name=option.name)) + res.append(' opts.{module}.{name}WasSetByUser = true;'.format( + module=module.id, name=option.name)) + return '\n '.join(res) def generate_getinfo_impl(modules): @@ -431,7 +404,7 @@ def generate_module_mode_decl(module): """Generates the declarations of mode enums and utility functions.""" res = [] for option in module.options: - if option.name is None or not option.mode: + if not option.mode: continue values = list(option.mode.keys()) res.append( @@ -523,12 +496,12 @@ def generate_module_mode_impl(module): """Generates the declarations of mode enums and utility functions.""" res = [] for option in module.options: - if option.name is None or not option.mode: + if not option.mode: continue cases = [ 'case {type}::{enum}: return os << "{name}";'.format( type=option.type, enum=enum, name=info[0]['name']) - for enum,info in option.mode.items() + for enum, info in option.mode.items() ] res.append( TPL_MODE_STREAM_OPERATOR.format(type=option.type, @@ -566,7 +539,7 @@ def generate_module_mode_impl(module): def _add_cmdoption(option, name, opts, next_id): fmt = { 'name': name, - 'arg': 'no' if option.type in ['bool', 'void'] else 'required', + 'arg': 'no' if option.type == 'bool' else 'required', 'next_id': next_id } opts.append( @@ -590,7 +563,7 @@ def generate_parsing(modules): needs_impl = True code.append("case '{0}': // -{0}".format(option.short)) short += option.short - if option.type not in ['bool', 'void']: + if option.type != 'bool': short += ':' if option.long: # long option needs_impl = True @@ -609,9 +582,6 @@ def generate_parsing(modules): if option.type == 'bool': code.append(' solver.setOption("{}", "true"); break;'.format( option.long_name)) - elif option.type == 'void': - code.append(' solver.setOption("{}", ""); break;'.format( - option.long_name)) else: code.append( ' solver.setOption("{}", optionarg); break;'.format( @@ -824,14 +794,14 @@ def generate_sphinx_help(modules): def generate_sphinx_output_tags(modules, src_dir, build_dir): """Render help for the --output option for sphinx.""" base = next(filter(lambda m: m.id == 'base', modules)) - opt = next(filter(lambda o: o.name == 'outputTag', base.options)) + opt = next(filter(lambda o: o.long == 'output=TAG', base.options)) # The programoutput extension has weird semantics about the cwd: # https://sphinxcontrib-programoutput.readthedocs.io/en/latest/#usage cwd = '/' + os.path.relpath(build_dir, src_dir) res = [] - for name,info in opt.mode.items(): + for name, info in opt.mode.items(): info = info[0] if 'description' not in info: continue @@ -1002,9 +972,9 @@ class Checker: self.__check_option_long(o, o.long_name) if o.alternate: self.__check_option_long(o, 'no-' + o.long_name) - if o.type in ['bool', 'void'] and '=' in o.long: - self.perr('must not have an argument description', option=o) - if o.type not in ['bool', 'void'] and not '=' in o.long: + if o.type == 'bool' and '=' in o.long: + self.perr('bool options must not have an argument description', option=o) + if o.type != 'bool' and not '=' in o.long: self.perr("needs argument description ('{}=...')", o.long, option=o) |