From: Gereon Kremer Date: Fri, 3 Sep 2021 18:26:29 +0000 (-0700) Subject: Check that alternate is only set for bool (#7125) X-Git-Tag: cvc5-1.0.0~1273 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b500a7fd94cafc55f680f432ef35d6d927f13518;p=cvc5.git Check that alternate is only set for bool (#7125) This PR slightly changes how the alternate option property is handled and explicitly checks that alternate is only set for bool options. --- diff --git a/src/options/mkoptions.py b/src/options/mkoptions.py index bb5de4dea..6265ca7b1 100644 --- a/src/options/mkoptions.py +++ b/src/options/mkoptions.py @@ -258,21 +258,17 @@ class Module(object): class Option(object): - """Module option. - - An instance of this class corresponds to an option defined in a - MODULE_options.toml configuration file specified via [[option]]. - """ + """Represents on option.""" def __init__(self, d): self.__dict__ = dict((k, None) for k in OPTION_ATTR_ALL) self.includes = [] self.predicates = [] - self.alternate = True # add --no- alternative long option for bool - self.filename = None for (attr, val) in d.items(): assert attr in self.__dict__ if attr == 'alternate' or val: self.__dict__[attr] = val + if self.type == 'bool' and self.alternate is None: + self.alternate = True self.long_name = None self.long_opt = None if self.long: @@ -377,7 +373,7 @@ class SphinxGenerator: 'name': names, 'help': option.help, 'expert': option.category == 'expert', - 'alternate': option.type == 'bool' and option.alternate, + 'alternate': option.alternate, 'help_mode': option.help_mode, 'modes': modes, } @@ -726,7 +722,7 @@ def docgen_option(option, help_common, help_others): # Generate documentation for cmdline options if opts and option.category != 'undocumented': help_cmd = help_msg - if option.type == 'bool' and option.alternate: + if option.alternate: help_cmd += ' [*]' res = help_format(help_cmd, opts) @@ -902,7 +898,7 @@ def codegen_all_modules(modules, build_dir, dst_dir, tpls): h.format(handler=option.handler, smtname=option.long_name)) # Add --no- alternative options for boolean options - if option.long and option.type == 'bool' and option.alternate: + if option.long and option.alternate: cases = [] cases.append( 'case {}: // --no-{}'.format( @@ -1038,6 +1034,8 @@ def parse_module(filename, module): perr(filename, "invalid default value '{}'".format(option.default), option) + if option.alternate and option.type != 'bool': + perr(filename, 'is alternate but not bool', option) if option.short and not option.long: perr(filename, "short option '{}' specified but no long option".format( @@ -1055,7 +1053,6 @@ def parse_module(filename, module): perr(filename, 'help text required for {} options'.format(option.category), option) - option.filename = filename res.options.append(option) return res