1 /******************************************************************************
2 * Top contributors (to current version):
3 * Tim King, Gereon Kremer, Andrew Reynolds
5 * This file is part of the cvc5 project.
7 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 * in the top-level source directory and their institutional affiliations.
9 * All rights reserved. See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
13 * Global (command-line, set-option, ...) parameters for SMT.
16 #include "base/check.h"
17 #include "base/output.h"
18 #include "options/options.h"
19 #include "options/options_handler.h"
20 #include "options/options_listener.h"
21 #include "options/options_public.h"
22 #include "options/uf_options.h"
33 namespace cvc5::options
35 // Contains the default option handlers (i.e. parsers)
39 * Utility function for handling numeric options. Takes care of checking for
40 * unsignedness, parsing and handling parsing exceptions. Expects `conv` to be
41 * a conversion function like `std::stod`, accepting a `std::string` and a
42 * `size_t*`. The argument `type` is only used to generate proper error
43 * messages and should be the string representation of `T`. If `T` is
44 * unsigned, checks that `optionarg` contains no minus. Then `conv` is called
45 * and the error conditions are handled: `conv` may throw an exception or
46 * `pos` may be smaller than the size of `optionarg`, indicating that not the
47 * entirety of `optionarg` was parsed.
49 template <typename T
, typename FF
>
50 T
parseNumber(const std::string
& flag
,
51 const std::string
& optionarg
,
53 const std::string
& type
)
55 if (!std::numeric_limits
<T
>::is_signed
56 && (optionarg
.find('-') != std::string::npos
))
59 ss
<< "Argument '" << optionarg
<< "' for " << type
<< " option " << flag
61 throw OptionException(ss
.str());
67 res
= conv(optionarg
, &pos
);
69 catch (const std::exception
& e
)
72 ss
<< "Argument '" << optionarg
<< "' for " << type
<< " option " << flag
73 << " did not parse as " << type
;
74 throw OptionException(ss
.str());
76 if (pos
< optionarg
.size())
79 ss
<< "Argument '" << optionarg
<< "' for " << type
<< " option " << flag
80 << " did parse only partially as " << type
<< ", leaving '"
81 << optionarg
.substr(pos
) << "'";
82 throw OptionException(ss
.str());
87 /** Default handler that triggers a compiler error */
89 T
handleOption(const std::string
& option
,
90 const std::string
& flag
,
91 const std::string
& optionarg
)
93 T::unsupported_handleOption_specialization
;
94 return *static_cast<T
*>(nullptr);
97 /** Handle a string option by returning it as is. */
99 std::string handleOption
<std::string
>(const std::string
& option
,
100 const std::string
& flag
,
101 const std::string
& optionarg
)
105 /** Handle a bool option, recognizing "true" or "false". */
107 bool handleOption
<bool>(const std::string
& option
,
108 const std::string
& flag
,
109 const std::string
& optionarg
)
111 if (optionarg
== "true")
115 if (optionarg
== "false")
119 throw OptionException("Argument '" + optionarg
+ "' for bool option " + flag
120 + " is not a bool constant");
123 /** Handle a double option, using `parseNumber` with `std::stod`. */
125 double handleOption
<double>(const std::string
& option
,
126 const std::string
& flag
,
127 const std::string
& optionarg
)
129 return parseNumber
<double>(
132 [](const auto& s
, auto p
) { return std::stod(s
, p
); },
136 /** Handle a int64_t option, using `parseNumber` with `std::stoll`. */
138 int64_t handleOption
<int64_t>(const std::string
& option
,
139 const std::string
& flag
,
140 const std::string
& optionarg
)
142 return parseNumber
<int64_t>(
145 [](const auto& s
, auto p
) { return std::stoll(s
, p
); },
149 /** Handle a uint64_t option, using `parseNumber` with `std::stoull`. */
151 uint64_t handleOption
<uint64_t>(const std::string
& option
,
152 const std::string
& flag
,
153 const std::string
& optionarg
)
155 return parseNumber
<uint64_t>(
158 [](const auto& s
, auto p
) { return std::stoull(s
, p
); },
162 /** Handle a ManagedIn option. */
164 ManagedIn handleOption
<ManagedIn
>(const std::string
& option
,
165 const std::string
& flag
,
166 const std::string
& optionarg
)
173 /** Handle a ManagedErr option. */
175 ManagedErr handleOption
<ManagedErr
>(const std::string
& option
,
176 const std::string
& flag
,
177 const std::string
& optionarg
)
184 /** Handle a ManagedOut option. */
186 ManagedOut handleOption
<ManagedOut
>(const std::string
& option
,
187 const std::string
& flag
,
188 const std::string
& optionarg
)
196 std::vector
<std::string
> getNames()
205 std::string
get(const Options
& options
, const std::string
& name
)
207 Trace("options") << "Options::getOption(" << name
<< ")" << std::endl
;
211 throw OptionException("Unrecognized option key or setting: " + name
);
215 Options
& opts
, const std::string
& name
, const std::string
& optionarg
)
217 Trace("options") << "set option " << name
<< " = " << optionarg
225 throw OptionException("Unrecognized option key or setting: " + name
);
229 #if defined(CVC5_MUZZLED) || defined(CVC5_COMPETITION_MODE)
230 #define DO_SEMANTIC_CHECKS_BY_DEFAULT false
231 #else /* CVC5_MUZZLED || CVC5_COMPETITION_MODE */
232 #define DO_SEMANTIC_CHECKS_BY_DEFAULT true
233 #endif /* CVC5_MUZZLED || CVC5_COMPETITION_MODE */
235 OptionInfo
getInfo(const Options
& opts
, const std::string
& name
)
240 return OptionInfo
{"", {}, false, OptionInfo::VoidInfo
{}};
243 #undef DO_SEMANTIC_CHECKS_BY_DEFAULT
245 } // namespace cvc5::options