1 /********************* */
2 /*! \file options_template.cpp
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Mathias Preiner
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2018 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.\endverbatim
12 ** \brief Contains code for handling command-line options.
14 ** Contains code for handling command-line options
17 #if !defined(_BSD_SOURCE) && defined(__MINGW32__) && !defined(__MINGW64__)
18 // force use of optreset; mingw32 croaks on argv-switching otherwise
19 # include "cvc4autoconfig.h"
21 # undef HAVE_DECL_OPTRESET
22 # define HAVE_DECL_OPTRESET 1
23 # define CVC4_IS_NOT_REALLY_BSD
24 #endif /* !_BSD_SOURCE && __MINGW32__ && !__MINGW64__ */
28 #endif /* __MINGW64__ */
33 #ifdef CVC4_IS_NOT_REALLY_BSD
35 #endif /* CVC4_IS_NOT_REALLY_BSD */
51 #include "base/cvc4_assert.h"
52 #include "base/exception.h"
53 #include "base/output.h"
54 #include "options/argument_extender.h"
55 #include "options/argument_extender_implementation.h"
56 #include "options/didyoumean.h"
57 #include "options/language.h"
58 #include "options/options_handler.h"
63 #include "options/options_holder.h"
64 #include "cvc4autoconfig.h"
65 #include "options/base_handlers.h"
71 using namespace CVC4::options
;
75 thread_local Options
* Options::s_current
= NULL
;
80 * This is a default handler for options of built-in C++ type. This
81 * template is really just a helper for the handleOption() template,
82 * below. Variants of this template handle numeric and non-numeric,
83 * integral and non-integral, signed and unsigned C++ types.
84 * handleOption() makes sure to instantiate the right one.
86 * This implements default behavior when e.g. an option is
87 * unsigned but the user specifies a negative argument; etc.
89 template <class T
, bool is_numeric
, bool is_integer
>
90 struct OptionHandler
{
91 static T
handle(std::string option
, std::string optionarg
);
92 };/* struct OptionHandler<> */
94 /** Variant for integral C++ types */
96 struct OptionHandler
<T
, true, true> {
97 static bool stringToInt(T
& t
, const std::string
& str
) {
98 std::istringstream
ss(str
);
101 return !(ss
.fail() || ss
.get(tmp
));
104 static bool containsMinus(const std::string
& str
) {
105 return str
.find('-') != std::string::npos
;
108 static T
handle(const std::string
& option
, const std::string
& optionarg
) {
111 bool success
= stringToInt(i
, optionarg
);
114 throw OptionException(option
+ ": failed to parse "+ optionarg
+
115 " as an integer of the appropriate type.");
118 // Depending in the platform unsigned numbers with '-' signs may parse.
119 // Reject these by looking for any minus if it is not signed.
120 if( (! std::numeric_limits
<T
>::is_signed
) && containsMinus(optionarg
) ) {
121 // unsigned type but user gave negative argument
122 throw OptionException(option
+ " requires a nonnegative argument");
123 } else if(i
< std::numeric_limits
<T
>::min()) {
124 // negative overflow for type
125 std::stringstream ss
;
126 ss
<< option
<< " requires an argument >= "
127 << std::numeric_limits
<T
>::min();
128 throw OptionException(ss
.str());
129 } else if(i
> std::numeric_limits
<T
>::max()) {
130 // positive overflow for type
131 std::stringstream ss
;
132 ss
<< option
<< " requires an argument <= "
133 << std::numeric_limits
<T
>::max();
134 throw OptionException(ss
.str());
139 // if(std::numeric_limits<T>::is_signed) {
140 // return T(i.getLong());
142 // return T(i.getUnsignedLong());
144 } catch(std::invalid_argument
&) {
145 // user gave something other than an integer
146 throw OptionException(option
+ " requires an integer argument");
149 };/* struct OptionHandler<T, true, true> */
151 /** Variant for numeric but non-integral C++ types */
153 struct OptionHandler
<T
, true, false> {
154 static T
handle(std::string option
, std::string optionarg
) {
155 std::stringstream
in(optionarg
);
159 // we didn't consume the whole string (junk at end)
160 throw OptionException(option
+ " requires a numeric argument");
163 if(! std::numeric_limits
<T
>::is_signed
&& r
< 0.0) {
164 // unsigned type but user gave negative value
165 throw OptionException(option
+ " requires a nonnegative argument");
166 } else if(r
< -std::numeric_limits
<T
>::max()) {
167 // negative overflow for type
168 std::stringstream ss
;
169 ss
<< option
<< " requires an argument >= "
170 << -std::numeric_limits
<T
>::max();
171 throw OptionException(ss
.str());
172 } else if(r
> std::numeric_limits
<T
>::max()) {
173 // positive overflow for type
174 std::stringstream ss
;
175 ss
<< option
<< " requires an argument <= "
176 << std::numeric_limits
<T
>::max();
177 throw OptionException(ss
.str());
182 };/* struct OptionHandler<T, true, false> */
184 /** Variant for non-numeric C++ types */
186 struct OptionHandler
<T
, false, false> {
187 static T
handle(std::string option
, std::string optionarg
) {
188 T::unsupported_handleOption_call___please_write_me
;
189 // The above line causes a compiler error if this version of the template
190 // is ever instantiated (meaning that a specialization is missing). So
191 // don't worry about the segfault in the next line, the "return" is only
192 // there to keep the compiler from giving additional, distracting errors
196 };/* struct OptionHandler<T, false, false> */
198 /** Handle an option of type T in the default way. */
200 T
handleOption(std::string option
, std::string optionarg
) {
201 return OptionHandler
<T
, std::numeric_limits
<T
>::is_specialized
, std::numeric_limits
<T
>::is_integer
>::handle(option
, optionarg
);
204 /** Handle an option of type std::string in the default way. */
206 std::string handleOption
<std::string
>(std::string option
, std::string optionarg
) {
211 * Run handler, and any user-given predicates, for option T.
212 * If a user specifies a :handler or :predicates, it overrides this.
215 typename
T::type
runHandlerAndPredicates(T
, std::string option
, std::string optionarg
, options::OptionsHandler
* handler
) {
216 // By default, parse the option argument in a way appropriate for its type.
217 // E.g., for "unsigned int" options, ensure that the provided argument is
218 // a nonnegative integer that fits in the unsigned int type.
220 return handleOption
<typename
T::type
>(option
, optionarg
);
224 void runBoolPredicates(T
, std::string option
, bool b
, options::OptionsHandler
* handler
) {
225 // By default, nothing to do for bool. Users add things with
226 // :predicate in options files to provide custom checking routines
227 // that can throw exceptions.
232 : d_holder(new options::OptionsHolder())
233 , d_handler(new options::OptionsHandler(this))
234 , d_forceLogicListeners()
235 , d_beforeSearchListeners()
236 , d_tlimitListeners()
237 , d_tlimitPerListeners()
238 , d_rlimitListeners()
239 , d_rlimitPerListeners()
242 Options::~Options() {
247 void Options::copyValues(const Options
& options
){
248 if(this != &options
) {
250 d_holder
= new options::OptionsHolder(*options
.d_holder
);
254 std::string
Options::formatThreadOptionException(const std::string
& option
) {
255 std::stringstream ss
;
256 ss
<< "can't understand option `" << option
257 << "': expected something like --threadN=\"--option1 --option2\","
258 << " where N is a nonnegative integer";
262 ListenerCollection::Registration
* Options::registerAndNotify(
263 ListenerCollection
& collection
, Listener
* listener
, bool notify
)
265 ListenerCollection::Registration
* registration
=
266 collection
.registerListener(listener
);
272 catch (OptionException
& e
)
274 // It can happen that listener->notify() throws an OptionException. In
275 // that case, we have to make sure that we delete the registration of our
276 // listener before rethrowing the exception. Otherwise the
277 // ListenerCollection deconstructor will complain that not all
278 // registrations have been removed before invoking the deconstructor.
280 throw OptionException(e
.getRawMessage());
286 ListenerCollection::Registration
* Options::registerForceLogicListener(
287 Listener
* listener
, bool notifyIfSet
)
289 bool notify
= notifyIfSet
&& wasSetByUser(options::forceLogicString
);
290 return registerAndNotify(d_forceLogicListeners
, listener
, notify
);
293 ListenerCollection::Registration
* Options::registerBeforeSearchListener(
296 return d_beforeSearchListeners
.registerListener(listener
);
299 ListenerCollection::Registration
* Options::registerTlimitListener(
300 Listener
* listener
, bool notifyIfSet
)
302 bool notify
= notifyIfSet
&&
303 wasSetByUser(options::cumulativeMillisecondLimit
);
304 return registerAndNotify(d_tlimitListeners
, listener
, notify
);
307 ListenerCollection::Registration
* Options::registerTlimitPerListener(
308 Listener
* listener
, bool notifyIfSet
)
310 bool notify
= notifyIfSet
&& wasSetByUser(options::perCallMillisecondLimit
);
311 return registerAndNotify(d_tlimitPerListeners
, listener
, notify
);
314 ListenerCollection::Registration
* Options::registerRlimitListener(
315 Listener
* listener
, bool notifyIfSet
)
317 bool notify
= notifyIfSet
&& wasSetByUser(options::cumulativeResourceLimit
);
318 return registerAndNotify(d_rlimitListeners
, listener
, notify
);
321 ListenerCollection::Registration
* Options::registerRlimitPerListener(
322 Listener
* listener
, bool notifyIfSet
)
324 bool notify
= notifyIfSet
&& wasSetByUser(options::perCallResourceLimit
);
325 return registerAndNotify(d_rlimitPerListeners
, listener
, notify
);
328 ListenerCollection::Registration
* Options::registerUseTheoryListListener(
329 Listener
* listener
, bool notifyIfSet
)
331 bool notify
= notifyIfSet
&& wasSetByUser(options::useTheoryList
);
332 return registerAndNotify(d_useTheoryListListeners
, listener
, notify
);
335 ListenerCollection::Registration
* Options::registerSetDefaultExprDepthListener(
336 Listener
* listener
, bool notifyIfSet
)
338 bool notify
= notifyIfSet
&& wasSetByUser(options::defaultExprDepth
);
339 return registerAndNotify(d_setDefaultExprDepthListeners
, listener
, notify
);
342 ListenerCollection::Registration
* Options::registerSetDefaultExprDagListener(
343 Listener
* listener
, bool notifyIfSet
)
345 bool notify
= notifyIfSet
&& wasSetByUser(options::defaultDagThresh
);
346 return registerAndNotify(d_setDefaultDagThreshListeners
, listener
, notify
);
349 ListenerCollection::Registration
* Options::registerSetPrintExprTypesListener(
350 Listener
* listener
, bool notifyIfSet
)
352 bool notify
= notifyIfSet
&& wasSetByUser(options::printExprTypes
);
353 return registerAndNotify(d_setPrintExprTypesListeners
, listener
, notify
);
356 ListenerCollection::Registration
* Options::registerSetDumpModeListener(
357 Listener
* listener
, bool notifyIfSet
)
359 bool notify
= notifyIfSet
&& wasSetByUser(options::dumpModeString
);
360 return registerAndNotify(d_setDumpModeListeners
, listener
, notify
);
363 ListenerCollection::Registration
* Options::registerSetPrintSuccessListener(
364 Listener
* listener
, bool notifyIfSet
)
366 bool notify
= notifyIfSet
&& wasSetByUser(options::printSuccess
);
367 return registerAndNotify(d_setPrintSuccessListeners
, listener
, notify
);
370 ListenerCollection::Registration
* Options::registerDumpToFileNameListener(
371 Listener
* listener
, bool notifyIfSet
)
373 bool notify
= notifyIfSet
&& wasSetByUser(options::dumpToFileName
);
374 return registerAndNotify(d_dumpToFileListeners
, listener
, notify
);
377 ListenerCollection::Registration
*
378 Options::registerSetRegularOutputChannelListener(
379 Listener
* listener
, bool notifyIfSet
)
381 bool notify
= notifyIfSet
&& wasSetByUser(options::regularChannelName
);
382 return registerAndNotify(d_setRegularChannelListeners
, listener
, notify
);
385 ListenerCollection::Registration
*
386 Options::registerSetDiagnosticOutputChannelListener(
387 Listener
* listener
, bool notifyIfSet
)
389 bool notify
= notifyIfSet
&& wasSetByUser(options::diagnosticChannelName
);
390 return registerAndNotify(d_setDiagnosticChannelListeners
, listener
, notify
);
393 ListenerCollection::Registration
*
394 Options::registerSetReplayLogFilename(
395 Listener
* listener
, bool notifyIfSet
)
397 bool notify
= notifyIfSet
&& wasSetByUser(options::replayLogFilename
);
398 return registerAndNotify(d_setReplayFilenameListeners
, listener
, notify
);
405 # define USE_EARLY_TYPE_CHECKING_BY_DEFAULT true
406 #else /* CVC4_DEBUG */
407 # define USE_EARLY_TYPE_CHECKING_BY_DEFAULT false
408 #endif /* CVC4_DEBUG */
410 #if defined(CVC4_MUZZLED) || defined(CVC4_COMPETITION_MODE)
411 # define DO_SEMANTIC_CHECKS_BY_DEFAULT false
412 #else /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
413 # define DO_SEMANTIC_CHECKS_BY_DEFAULT true
414 #endif /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
416 options::OptionsHolder::OptionsHolder() :
422 static const std::string mostCommonOptionsDescription
= "\
423 Most commonly-used CVC4 options:\n"
427 static const std::string optionsDescription
= mostCommonOptionsDescription
+ "\n\
429 Additional CVC4 options:\n"
433 static const std::string optionsFootnote
= "\n\
434 [*] Each of these options has a --no-OPTIONNAME variant, which reverses the\n\
435 sense of the option.\n\
438 static const std::string languageDescription
=
440 Languages currently supported as arguments to the -L / --lang option:\n\
441 auto attempt to automatically determine language\n\
442 cvc4 | presentation | pl CVC4 presentation language\n\
443 smt1 | smtlib1 SMT-LIB format 1.2\n\
444 smt | smtlib | smt2 |\n\
445 smt2.0 | smtlib2 | smtlib2.0 SMT-LIB format 2.0\n\
446 smt2.5 | smtlib2.5 SMT-LIB format 2.5\n\
447 smt2.6 | smtlib2.6 SMT-LIB format 2.6\n\
448 smt2.6.1 | smtlib2.6.1 SMT-LIB format 2.6 with support for the strings standard\n\
449 tptp TPTP format (cnf and fof)\n\
450 sygus SyGuS format\n\
452 Languages currently supported as arguments to the --output-lang option:\n\
453 auto match output language to input language\n\
454 cvc4 | presentation | pl CVC4 presentation language\n\
455 cvc3 CVC3 presentation language\n\
456 smt | smtlib | smt2 |\n\
457 smt2.0 | smtlib2.0 | smtlib2 SMT-LIB format 2.0\n\
458 smt2.5 | smtlib2.5 SMT-LIB format 2.5\n\
459 smt2.6 | smtlib2.6 SMT-LIB format 2.6\n\
460 smt2.6.1 | smtlib2.6.1 SMT-LIB format 2.6 with support for the strings standard\n\
462 z3str SMT-LIB 2.0 with Z3-str string constraints\n\
463 ast internal format (simple syntax trees)\n\
466 std::string
Options::getDescription() const {
467 return optionsDescription
;
470 void Options::printUsage(const std::string msg
, std::ostream
& out
) {
471 out
<< msg
<< optionsDescription
<< std::endl
472 << optionsFootnote
<< std::endl
<< std::flush
;
475 void Options::printShortUsage(const std::string msg
, std::ostream
& out
) {
476 out
<< msg
<< mostCommonOptionsDescription
<< std::endl
477 << optionsFootnote
<< std::endl
478 << "For full usage, please use --help."
479 << std::endl
<< std::endl
<< std::flush
;
482 void Options::printLanguageHelp(std::ostream
& out
) {
483 out
<< languageDescription
<< std::flush
;
487 * This is a table of long options. By policy, each short option
488 * should have an equivalent long option (but the reverse isn't the
489 * case), so this table should thus contain all command-line options.
491 * Each option in this array has four elements:
493 * 1. the long option string
494 * 2. argument behavior for the option:
495 * no_argument - no argument permitted
496 * required_argument - an argument is expected
497 * optional_argument - an argument is permitted but not required
498 * 3. this is a pointer to an int which is set to the 4th entry of the
499 * array if the option is present; or NULL, in which case
500 * getopt_long() returns the 4th entry
501 * 4. the return value for getopt_long() when this long option (or the
502 * value to set the 3rd entry to; see #3)
504 * If you add something here, you should add it in src/main/usage.h
505 * also, to document it.
507 * If you add something that has a short option equivalent, you should
508 * add it to the getopt_long() call in parseOptions().
510 static struct option cmdlineOptions
[] = {
512 { NULL
, no_argument
, NULL
, '\0' }
513 };/* cmdlineOptions */
516 // static void preemptGetopt(int& argc, char**& argv, const char* opt) {
518 // Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl;
520 // AlwaysAssert(opt != NULL && *opt != '\0');
521 // AlwaysAssert(strlen(opt) <= maxoptlen);
525 // while(argv[i] != NULL && argv[i][0] != '\0') {
529 // if(argv[i] == NULL) {
530 // argv = (char**) realloc(argv, (i + 6) * sizeof(char*));
531 // for(unsigned j = i; j < i + 5; ++j) {
532 // argv[j] = (char*) malloc(sizeof(char) * maxoptlen);
533 // argv[j][0] = '\0';
535 // argv[i + 5] = NULL;
538 // strncpy(argv[i], opt, maxoptlen - 1);
539 // argv[i][maxoptlen - 1] = '\0'; // ensure NUL-termination even on overflow
544 /** Set a given Options* as "current" just for a particular scope. */
549 OptionsGuard(Options
** field
, Options
* opts
) :
557 };/* class OptionsGuard */
559 }/* CVC4::options namespace */
562 * Parse argc/argv and put the result into a CVC4::Options.
563 * The return value is what's left of the command line (that is, the
564 * non-option arguments).
566 * Throws OptionException on failures.
568 std::vector
<std::string
> Options::parseOptions(Options
* options
,
572 Assert(options
!= NULL
);
573 Assert(argv
!= NULL
);
575 options::OptionsGuard
guard(&s_current
, options
);
577 const char *progName
= argv
[0];
579 // To debug options parsing, you may prefer to simply uncomment this
580 // and recompile. Debug flags have not been parsed yet so these have
582 //DebugChannel.on("options");
584 Debug("options") << "Options::parseOptions == " << options
<< std::endl
;
585 Debug("options") << "argv == " << argv
<< std::endl
;
587 // Find the base name of the program.
588 const char *x
= strrchr(progName
, '/');
592 options
->d_holder
->binary_name
= std::string(progName
);
594 ArgumentExtender
* argumentExtender
= new ArgumentExtenderImplementation();
595 for(int position
= 1; position
< argc
; position
++) {
596 argumentExtender
->pushBackArgument(argv
[position
]);
599 std::vector
<std::string
> nonoptions
;
600 parseOptionsRecursive(options
, argumentExtender
, &nonoptions
);
601 if(Debug
.isOn("options")){
602 for(std::vector
<std::string
>::const_iterator i
= nonoptions
.begin(),
603 iend
= nonoptions
.end(); i
!= iend
; ++i
){
604 Debug("options") << "nonoptions " << *i
<< std::endl
;
608 delete argumentExtender
;
612 void Options::parseOptionsRecursive(Options
* options
,
613 ArgumentExtender
* extender
,
614 std::vector
<std::string
>* nonoptions
)
619 extender
->movePreemptionsToArguments();
620 extender
->pushFrontArgument("");
621 extender
->getArguments(&argc
, &argv
);
623 if(Debug
.isOn("options")) {
624 Debug("options") << "starting a new parseOptionsRecursive with "
625 << argc
<< " arguments" << std::endl
;
626 for( int i
= 0; i
< argc
; i
++ ){
627 Assert(argv
[i
] != NULL
);
628 Debug("options") << " argv[" << i
<< "] = " << argv
[i
] << std::endl
;
632 // Having this synonym simplifies the generation code in mkoptions.
633 options::OptionsHandler
* handler
= options
->d_handler
;
634 options::OptionsHolder
* holder
= options
->d_holder
;
636 // Reset getopt(), in the case of multiple calls to parseOptions().
637 // This can be = 1 in newer GNU getopt, but older (< 2007) require = 0.
639 #if HAVE_DECL_OPTRESET
640 optreset
= 1; // on BSD getopt() (e.g. Mac OS), might need this
641 #endif /* HAVE_DECL_OPTRESET */
648 while(true) { // Repeat Forever
650 if(extender
->hasPreemptions()){
651 // Stop this round of parsing. We now parse recursively
652 // to start on a new character array for argv.
653 parseOptionsRecursive(options
, extender
, nonoptions
);
658 std::string option
, optionarg
;
660 optind
= main_optind
;
661 old_optind
= main_optind
;
662 //optind_ref = &main_optind;
665 // If we encounter an element that is not at zero and does not start
666 // with a "-", this is a non-option. We consume this element as a
668 if (main_optind
> 0 && main_optind
< argc
&&
669 argv
[main_optind
][0] != '-') {
670 Debug("options") << "enqueueing " << argv
[main_optind
]
671 << " as a non-option." << std::endl
;
672 nonoptions
->push_back(argv
[main_optind
]);
674 extender
->popFrontArgument();
679 Debug("options") << "[ before, main_optind == " << main_optind
<< " ]"
681 Debug("options") << "[ before, optind == " << optind
<< " ]" << std::endl
;
682 Debug("options") << "[ argc == " << argc
<< ", argv == " << argv
<< " ]"
684 int c
= getopt_long(argc
, argv
,
685 "+:${options_short}$",
686 cmdlineOptions
, NULL
);
688 while(main_optind
< optind
) {
690 extender
->popFrontArgument();
693 Debug("options") << "[ got " << int(c
) << " (" << char(c
) << ") ]"
694 << "[ next option will be at pos: " << optind
<< " ]"
697 // The initial getopt_long call should always determine that argv[0]
698 // is not an option and returns -1. We always manually advance beyond
701 // We have to reinitialize optind to 0 instead of 1 as we need to support
702 // changing the argv array passed to getopt.
703 // This is needed as are using GNU extensions.
704 // From: http://man7.org/linux/man-pages/man3/getopt.3.html
705 // A program that scans multiple argument vectors, or rescans the same
706 // vector more than once, and wants to make use of GNU extensions such
707 // as '+' and '-' at the start of optstring, or changes the value of
708 // POSIXLY_CORRECT between scans, must reinitialize getopt() by
709 // resetting optind to 0, rather than the traditional value of 1.
710 // (Resetting to 0 forces the invocation of an internal initialization
711 // routine that rechecks POSIXLY_CORRECT and checks for GNU extensions
713 if ( old_optind
== 0 && c
== -1 ) {
714 Assert(main_optind
> 0);
719 if(Debug
.isOn("options")) {
720 Debug("options") << "done with option parsing" << std::endl
;
721 for(int index
= optind
; index
< argc
; ++index
) {
722 Debug("options") << "remaining " << argv
[index
] << std::endl
;
728 option
= argv
[old_optind
== 0 ? 1 : old_optind
];
729 optionarg
= (optarg
== NULL
) ? "" : optarg
;
731 Debug("preemptGetopt") << "processing option " << c
732 << " (`" << char(c
) << "'), " << option
<< std::endl
;
739 // This can be a long or short option, and the way to get at the
740 // name of it is different.
741 throw OptionException(std::string("option `") + option
+
742 "' missing its required argument");
747 ( optopt
>= $
{option_value_begin
}$
&&
748 optopt
<= $
{option_value_end
}$
)
749 ) && !strncmp(argv
[optind
- 1], "--thread", 8) &&
750 strlen(argv
[optind
- 1]) > 8 )
752 if(! isdigit(argv
[optind
- 1][8])) {
753 throw OptionException(formatThreadOptionException(option
));
755 std::vector
<std::string
>& threadArgv
= holder
->threadArgv
;
757 long tnum
= strtol(argv
[optind
- 1] + 8, &end
, 10);
758 if(tnum
< 0 || (*end
!= '\0' && *end
!= '=')) {
759 throw OptionException(formatThreadOptionException(option
));
761 if(threadArgv
.size() <= size_t(tnum
)) {
762 threadArgv
.resize(tnum
+ 1);
764 if(threadArgv
[tnum
] != "") {
765 threadArgv
[tnum
] += " ";
767 if(*end
== '\0') { // e.g., we have --thread0 "foo"
769 throw OptionException(std::string("option `") + option
+
770 "' missing its required argument");
772 Debug("options") << "thread " << tnum
<< " gets option "
773 << argv
[optind
] << std::endl
;
774 threadArgv
[tnum
] += argv
[main_optind
];
776 } else { // e.g., we have --thread0="foo"
778 throw OptionException(std::string("option `") + option
+
779 "' missing its required argument");
781 Debug("options") << "thread " << tnum
<< " gets option "
782 << (end
+ 1) << std::endl
;
783 threadArgv
[tnum
] += end
+ 1;
785 Debug("options") << "thread " << tnum
<< " now has "
786 << threadArgv
[tnum
] << std::endl
;
790 throw OptionException(std::string("can't understand option `") + option
+
791 "'" + suggestCommandLineOptions(option
));
795 Debug("options") << "got " << nonoptions
->size()
796 << " non-option arguments." << std::endl
;
801 std::string
Options::suggestCommandLineOptions(const std::string
& optionName
)
803 DidYouMean didYouMean
;
806 for(size_t i
= 0; (opt
= cmdlineOptions
[i
].name
) != NULL
; ++i
) {
807 didYouMean
.addWord(std::string("--") + cmdlineOptions
[i
].name
);
810 return didYouMean
.getMatchAsString(optionName
.substr(0, optionName
.find('=')));
813 static const char* smtOptions
[] = {
818 std::vector
<std::string
> Options::suggestSmtOptions(
819 const std::string
& optionName
)
821 std::vector
<std::string
> suggestions
;
824 for(size_t i
= 0; (opt
= smtOptions
[i
]) != NULL
; ++i
) {
825 if(std::strstr(opt
, optionName
.c_str()) != NULL
) {
826 suggestions
.push_back(opt
);
833 std::vector
<std::vector
<std::string
> > Options::getOptions() const
835 std::vector
< std::vector
<std::string
> > opts
;
837 $
{options_getoptions
}$
843 void Options::setOption(const std::string
& key
, const std::string
& optionarg
)
845 options::OptionsHandler
* handler
= d_handler
;
846 Options
*options
= Options::current();
847 Trace("options") << "SMT setOption(" << key
<< ", " << optionarg
<< ")"
850 $
{setoption_handlers
}$
853 throw UnrecognizedOptionException(key
);
856 std::string
Options::getOption(const std::string
& key
) const
858 Trace("options") << "SMT getOption(" << key
<< ")" << std::endl
;
860 $
{getoption_handlers
}$
863 throw UnrecognizedOptionException(key
);
866 #undef USE_EARLY_TYPE_CHECKING_BY_DEFAULT
867 #undef DO_SEMANTIC_CHECKS_BY_DEFAULT