This PR replaces some option predicates by explicit minimum and maximum values. This allows us to export information about an options domain/range in the future.
OPTION_ATTR_ALL = OPTION_ATTR_REQ + [
'name', 'short', 'long', 'alias',
'default', 'alternate', 'mode',
- 'handler', 'predicates', 'includes',
+ 'handler', 'predicates', 'includes', 'minimum', 'maximum',
'help', 'help_mode'
]
def get_predicates(option):
"""Render predicate calls for assignment functions"""
- if not option.predicates:
+ if option.type == 'void':
return []
optname = option.long_name if option.long else ""
assert option.type != 'void'
- return ['opts.handler().{}("{}", option, value);'.format(x, optname)
+ res = ['opts.handler().{}("{}", option, value);'.format(x, optname)
for x in option.predicates]
+ if option.minimum:
+ res.append('opts.handler().checkMinimum("{}", option, value, {});'.format(optname, option.minimum))
+ if option.maximum:
+ res.append('opts.handler().checkMaximum("{}", option, value, {});'.format(optname, option.maximum))
+ return res
def get_getall(module, option):
OptionsHandler(Options* options);
template <typename T>
- void geqZero(const std::string& option,
- const std::string& flag,
- T value) const
+ void checkMinimum(const std::string& option,
+ const std::string& flag,
+ T value,
+ T minimum) const
{
- if (value < 0)
+ if (value < minimum)
{
std::stringstream ss;
- ss << flag << ": " << value << " is not a legal setting, should be "
- << value << " >= 0.";
+ ss << flag << " = " << value
+ << " is not a legal setting, value should be at least " << minimum
+ << ".";
throw OptionException(ss.str());
}
}
template <typename T>
- void betweenZeroAndOne(const std::string& option,
- const std::string& flag,
- T value) const
+ void checkMaximum(const std::string& option,
+ const std::string& flag,
+ T value,
+ T maximum) const
{
- if (value < 0 || value > 1)
+ if (value > maximum)
{
std::stringstream ss;
- ss << flag << ": " << value
- << " is not a legal setting, should be 0 <= " << flag << " <= 1.";
+ ss << flag << " = " << value
+ << " is not a legal setting, value should be at most " << maximum
+ << ".";
throw OptionException(ss.str());
}
}
long = "random-freq=P"
type = "double"
default = "0.0"
- predicates = ["betweenZeroAndOne"]
+ minimum = "0.0"
+ maximum = "1.0"
help = "sets the frequency of random decisions in the sat solver (P=0.0 by default)"
[[option]]
category = "regular"
type = "double"
default = "0.95"
- predicates = ["betweenZeroAndOne"]
+ minimum = "0.0"
+ maximum = "1.0"
help = "variable activity decay factor for Minisat"
[[option]]
category = "regular"
type = "double"
default = "0.999"
- predicates = ["betweenZeroAndOne"]
+ minimum = "0.0"
+ maximum = "1.0"
help = "clause activity decay factor for Minisat"
[[option]]
long = "restart-int-inc=F"
type = "double"
default = "3.0"
- predicates = ["geqZero"]
+ minimum = "0.0"
help = "sets the restart interval increase factor for the sat solver (F=3.0 by default)"
[[option]]