1 /********************* */
2 /*! \file options_template.cpp
4 ** Original author: Morgan Deters
5 ** Major contributors: none
6 ** Minor contributors (to current version): Kshitij Bansal
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** 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"
55 #include "options/argument_extender.h"
56 #include "options/didyoumean.h"
57 #include "options/language.h"
58 #include "options/options_handler.h"
60 $
{include_all_option_headers
}
62 #line 63 "${template}"
64 #include "options/options_holder.h"
65 #include "cvc4autoconfig.h"
66 #include "options/base_handlers.h"
68 $
{option_handler_includes
}
70 #line 71 "${template}"
73 using namespace CVC4::options
;
77 CVC4_THREADLOCAL(Options
*) Options::s_current
= NULL
;
82 * This is a default handler for options of built-in C++ type. This
83 * template is really just a helper for the handleOption() template,
84 * below. Variants of this template handle numeric and non-numeric,
85 * integral and non-integral, signed and unsigned C++ types.
86 * handleOption() makes sure to instantiate the right one.
88 * This implements default behavior when e.g. an option is
89 * unsigned but the user specifies a negative argument; etc.
91 template <class T
, bool is_numeric
, bool is_integer
>
92 struct OptionHandler
{
93 static T
handle(std::string option
, std::string optionarg
);
94 };/* struct OptionHandler<> */
96 /** Variant for integral C++ types */
98 struct OptionHandler
<T
, true, true> {
99 static bool stringToInt(T
& t
, const std::string
& str
) {
100 std::istringstream
ss(str
);
103 return !(ss
.fail() || ss
.get(tmp
));
106 static bool containsMinus(const std::string
& str
) {
107 return str
.find('-') != std::string::npos
;
110 static T
handle(const std::string
& option
, const std::string
& optionarg
) {
113 bool success
= stringToInt(i
, optionarg
);
116 throw OptionException(option
+ ": failed to parse "+ optionarg
+
117 " as an integer of the appropraite type.");
120 // Depending in the platform unsigned numbers with '-' signs may parse.
121 // Reject these by looking for any minus if it is not signed.
122 if( (! std::numeric_limits
<T
>::is_signed
) && containsMinus(optionarg
) ) {
123 // unsigned type but user gave negative argument
124 throw OptionException(option
+ " requires a nonnegative argument");
125 } else if(i
< std::numeric_limits
<T
>::min()) {
126 // negative overflow for type
127 std::stringstream ss
;
128 ss
<< option
<< " requires an argument >= "
129 << std::numeric_limits
<T
>::min();
130 throw OptionException(ss
.str());
131 } else if(i
> std::numeric_limits
<T
>::max()) {
132 // positive overflow for type
133 std::stringstream ss
;
134 ss
<< option
<< " requires an argument <= "
135 << std::numeric_limits
<T
>::max();
136 throw OptionException(ss
.str());
141 // if(std::numeric_limits<T>::is_signed) {
142 // return T(i.getLong());
144 // return T(i.getUnsignedLong());
146 } catch(std::invalid_argument
&) {
147 // user gave something other than an integer
148 throw OptionException(option
+ " requires an integer argument");
151 };/* struct OptionHandler<T, true, true> */
153 /** Variant for numeric but non-integral C++ types */
155 struct OptionHandler
<T
, true, false> {
156 static T
handle(std::string option
, std::string optionarg
) {
157 std::stringstream
in(optionarg
);
161 // we didn't consume the whole string (junk at end)
162 throw OptionException(option
+ " requires a numeric argument");
165 if(! std::numeric_limits
<T
>::is_signed
&& r
< 0.0) {
166 // unsigned type but user gave negative value
167 throw OptionException(option
+ " requires a nonnegative argument");
168 } else if(r
< -std::numeric_limits
<T
>::max()) {
169 // negative overflow for type
170 std::stringstream ss
;
171 ss
<< option
<< " requires an argument >= "
172 << -std::numeric_limits
<T
>::max();
173 throw OptionException(ss
.str());
174 } else if(r
> std::numeric_limits
<T
>::max()) {
175 // positive overflow for type
176 std::stringstream ss
;
177 ss
<< option
<< " requires an argument <= "
178 << std::numeric_limits
<T
>::max();
179 throw OptionException(ss
.str());
184 };/* struct OptionHandler<T, true, false> */
186 /** Variant for non-numeric C++ types */
188 struct OptionHandler
<T
, false, false> {
189 static T
handle(std::string option
, std::string optionarg
) {
190 T::unsupported_handleOption_call___please_write_me
;
191 // The above line causes a compiler error if this version of the template
192 // is ever instantiated (meaning that a specialization is missing). So
193 // don't worry about the segfault in the next line, the "return" is only
194 // there to keep the compiler from giving additional, distracting errors
198 };/* struct OptionHandler<T, false, false> */
200 /** Handle an option of type T in the default way. */
202 T
handleOption(std::string option
, std::string optionarg
) {
203 return OptionHandler
<T
, std::numeric_limits
<T
>::is_specialized
, std::numeric_limits
<T
>::is_integer
>::handle(option
, optionarg
);
206 /** Handle an option of type std::string in the default way. */
208 std::string handleOption
<std::string
>(std::string option
, std::string optionarg
) {
213 * Run handler, and any user-given predicates, for option T.
214 * If a user specifies a :handler or :predicates, it overrides this.
217 typename
T::type
runHandlerAndPredicates(T
, std::string option
, std::string optionarg
, options::OptionsHandler
* handler
) {
218 // By default, parse the option argument in a way appropriate for its type.
219 // E.g., for "unsigned int" options, ensure that the provided argument is
220 // a nonnegative integer that fits in the unsigned int type.
222 return handleOption
<typename
T::type
>(option
, optionarg
);
226 void runBoolPredicates(T
, std::string option
, bool b
, options::OptionsHandler
* handler
) {
227 // By default, nothing to do for bool. Users add things with
228 // :predicate in options files to provide custom checking routines
229 // that can throw exceptions.
234 : d_holder(new options::OptionsHolder())
235 , d_handler(new options::OptionsHandler(this))
236 , d_forceLogicListeners()
237 , d_beforeSearchListeners()
238 , d_tlimitListeners()
239 , d_tlimitPerListeners()
240 , d_rlimitListeners()
241 , d_rlimitPerListeners()
244 Options::~Options() {
249 void Options::copyValues(const Options
& options
){
250 if(this != &options
) {
252 d_holder
= new options::OptionsHolder(*options
.d_holder
);
256 std::string
Options::formatThreadOptionException(const std::string
& option
) {
257 std::stringstream ss
;
258 ss
<< "can't understand option `" << option
259 << "': expected something like --threadN=\"--option1 --option2\","
260 << " where N is a nonnegative integer";
264 ListenerCollection::Registration
* Options::registerAndNotify(
265 ListenerCollection
& collection
, Listener
* listener
, bool notify
)
267 ListenerCollection::Registration
* registration
=
268 collection
.registerListener(listener
);
275 ListenerCollection::Registration
* Options::registerForceLogicListener(
276 Listener
* listener
, bool notifyIfSet
)
278 bool notify
= notifyIfSet
&& wasSetByUser(options::forceLogicString
);
279 return registerAndNotify(d_forceLogicListeners
, listener
, notify
);
282 ListenerCollection::Registration
* Options::registerBeforeSearchListener(
285 return d_beforeSearchListeners
.registerListener(listener
);
288 ListenerCollection::Registration
* Options::registerTlimitListener(
289 Listener
* listener
, bool notifyIfSet
)
291 bool notify
= notifyIfSet
&&
292 wasSetByUser(options::cumulativeMillisecondLimit
);
293 return registerAndNotify(d_tlimitListeners
, listener
, notify
);
296 ListenerCollection::Registration
* Options::registerTlimitPerListener(
297 Listener
* listener
, bool notifyIfSet
)
299 bool notify
= notifyIfSet
&& wasSetByUser(options::perCallMillisecondLimit
);
300 return registerAndNotify(d_tlimitPerListeners
, listener
, notify
);
303 ListenerCollection::Registration
* Options::registerRlimitListener(
304 Listener
* listener
, bool notifyIfSet
)
306 bool notify
= notifyIfSet
&& wasSetByUser(options::cumulativeResourceLimit
);
307 return registerAndNotify(d_rlimitListeners
, listener
, notify
);
310 ListenerCollection::Registration
* Options::registerRlimitPerListener(
311 Listener
* listener
, bool notifyIfSet
)
313 bool notify
= notifyIfSet
&& wasSetByUser(options::perCallResourceLimit
);
314 return registerAndNotify(d_rlimitPerListeners
, listener
, notify
);
317 ListenerCollection::Registration
* Options::registerUseTheoryListListener(
318 Listener
* listener
, bool notifyIfSet
)
320 bool notify
= notifyIfSet
&& wasSetByUser(options::useTheoryList
);
321 return registerAndNotify(d_useTheoryListListeners
, listener
, notify
);
324 ListenerCollection::Registration
* Options::registerSetDefaultExprDepthListener(
325 Listener
* listener
, bool notifyIfSet
)
327 bool notify
= notifyIfSet
&& wasSetByUser(options::defaultExprDepth
);
328 return registerAndNotify(d_setDefaultExprDepthListeners
, listener
, notify
);
331 ListenerCollection::Registration
* Options::registerSetDefaultExprDagListener(
332 Listener
* listener
, bool notifyIfSet
)
334 bool notify
= notifyIfSet
&& wasSetByUser(options::defaultDagThresh
);
335 return registerAndNotify(d_setDefaultDagThreshListeners
, listener
, notify
);
338 ListenerCollection::Registration
* Options::registerSetPrintExprTypesListener(
339 Listener
* listener
, bool notifyIfSet
)
341 bool notify
= notifyIfSet
&& wasSetByUser(options::printExprTypes
);
342 return registerAndNotify(d_setPrintExprTypesListeners
, listener
, notify
);
345 ListenerCollection::Registration
* Options::registerSetDumpModeListener(
346 Listener
* listener
, bool notifyIfSet
)
348 bool notify
= notifyIfSet
&& wasSetByUser(options::dumpModeString
);
349 return registerAndNotify(d_setDumpModeListeners
, listener
, notify
);
352 ListenerCollection::Registration
* Options::registerSetPrintSuccessListener(
353 Listener
* listener
, bool notifyIfSet
)
355 bool notify
= notifyIfSet
&& wasSetByUser(options::printSuccess
);
356 return registerAndNotify(d_setPrintSuccessListeners
, listener
, notify
);
359 ListenerCollection::Registration
* Options::registerDumpToFileNameListener(
360 Listener
* listener
, bool notifyIfSet
)
362 bool notify
= notifyIfSet
&& wasSetByUser(options::dumpToFileName
);
363 return registerAndNotify(d_dumpToFileListeners
, listener
, notify
);
366 ListenerCollection::Registration
*
367 Options::registerSetRegularOutputChannelListener(
368 Listener
* listener
, bool notifyIfSet
)
370 bool notify
= notifyIfSet
&& wasSetByUser(options::regularChannelName
);
371 return registerAndNotify(d_setRegularChannelListeners
, listener
, notify
);
374 ListenerCollection::Registration
*
375 Options::registerSetDiagnosticOutputChannelListener(
376 Listener
* listener
, bool notifyIfSet
)
378 bool notify
= notifyIfSet
&& wasSetByUser(options::diagnosticChannelName
);
379 return registerAndNotify(d_setDiagnosticChannelListeners
, listener
, notify
);
382 ListenerCollection::Registration
*
383 Options::registerSetReplayLogFilename(
384 Listener
* listener
, bool notifyIfSet
)
386 bool notify
= notifyIfSet
&& wasSetByUser(options::replayLogFilename
);
387 return registerAndNotify(d_setReplayFilenameListeners
, listener
, notify
);
390 $
{all_custom_handlers
}
392 #line 393 "${template}"
395 # define USE_EARLY_TYPE_CHECKING_BY_DEFAULT true
396 #else /* CVC4_DEBUG */
397 # define USE_EARLY_TYPE_CHECKING_BY_DEFAULT false
398 #endif /* CVC4_DEBUG */
400 #if defined(CVC4_MUZZLED) || defined(CVC4_COMPETITION_MODE)
401 # define DO_SEMANTIC_CHECKS_BY_DEFAULT false
402 #else /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
403 # define DO_SEMANTIC_CHECKS_BY_DEFAULT true
404 #endif /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
406 options::OptionsHolder::OptionsHolder() : $
{all_modules_defaults
}
410 #line 411 "${template}"
412 static const std::string mostCommonOptionsDescription
= "\
413 Most commonly-used CVC4 options:${common_documentation}";
415 #line 416 "${template}"
417 static const std::string optionsDescription
= mostCommonOptionsDescription
+ "\n\
419 Additional CVC4 options:${remaining_documentation}";
421 #line 422 "${template}"
423 static const std::string optionsFootnote
= "\n\
424 [*] Each of these options has a --no-OPTIONNAME variant, which reverses the\n\
425 sense of the option.\n\
428 static const std::string languageDescription
= "\
429 Languages currently supported as arguments to the -L / --lang option:\n\
430 auto attempt to automatically determine language\n\
431 cvc4 | presentation | pl CVC4 presentation language\n\
432 smt1 | smtlib1 SMT-LIB format 1.2\n\
433 smt | smtlib | smt2 |\n\
434 smt2.0 | smtlib2 | smtlib2.0 SMT-LIB format 2.0\n\
435 smt2.5 | smtlib2.5 SMT-LIB format 2.5\n\
436 tptp TPTP format (cnf and fof)\n\
437 sygus SyGuS format\n\
439 Languages currently supported as arguments to the --output-lang option:\n\
440 auto match output language to input language\n\
441 cvc4 | presentation | pl CVC4 presentation language\n\
442 cvc3 CVC3 presentation language\n\
443 smt1 | smtlib1 SMT-LIB format 1.2\n\
444 smt | smtlib | smt2 |\n\
445 smt2.0 | smtlib2.0 | smtlib2 SMT-LIB format 2.0\n\
446 smt2.5 | smtlib2.5 SMT-LIB format 2.5\n\
448 z3str SMT-LIB 2.0 with Z3-str string constraints\n\
449 ast internal format (simple syntax trees)\n\
452 std::string
Options::getDescription() const {
453 return optionsDescription
;
456 void Options::printUsage(const std::string msg
, std::ostream
& out
) {
457 out
<< msg
<< optionsDescription
<< std::endl
458 << optionsFootnote
<< std::endl
<< std::flush
;
461 void Options::printShortUsage(const std::string msg
, std::ostream
& out
) {
462 out
<< msg
<< mostCommonOptionsDescription
<< std::endl
463 << optionsFootnote
<< std::endl
464 << "For full usage, please use --help."
465 << std::endl
<< std::endl
<< std::flush
;
468 void Options::printLanguageHelp(std::ostream
& out
) {
469 out
<< languageDescription
<< std::flush
;
473 * This is a table of long options. By policy, each short option
474 * should have an equivalent long option (but the reverse isn't the
475 * case), so this table should thus contain all command-line options.
477 * Each option in this array has four elements:
479 * 1. the long option string
480 * 2. argument behavior for the option:
481 * no_argument - no argument permitted
482 * required_argument - an argument is expected
483 * optional_argument - an argument is permitted but not required
484 * 3. this is a pointer to an int which is set to the 4th entry of the
485 * array if the option is present; or NULL, in which case
486 * getopt_long() returns the 4th entry
487 * 4. the return value for getopt_long() when this long option (or the
488 * value to set the 3rd entry to; see #3)
490 * If you add something here, you should add it in src/main/usage.h
491 * also, to document it.
493 * If you add something that has a short option equivalent, you should
494 * add it to the getopt_long() call in parseOptions().
496 static struct option cmdlineOptions
[] = {$
{all_modules_long_options
}
497 { NULL
, no_argument
, NULL
, '\0' }
498 };/* cmdlineOptions */
500 #line 501 "${template}"
502 // static void preemptGetopt(int& argc, char**& argv, const char* opt) {
504 // Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl;
506 // AlwaysAssert(opt != NULL && *opt != '\0');
507 // AlwaysAssert(strlen(opt) <= maxoptlen);
511 // while(argv[i] != NULL && argv[i][0] != '\0') {
515 // if(argv[i] == NULL) {
516 // argv = (char**) realloc(argv, (i + 6) * sizeof(char*));
517 // for(unsigned j = i; j < i + 5; ++j) {
518 // argv[j] = (char*) malloc(sizeof(char) * maxoptlen);
519 // argv[j][0] = '\0';
521 // argv[i + 5] = NULL;
524 // strncpy(argv[i], opt, maxoptlen - 1);
525 // argv[i][maxoptlen - 1] = '\0'; // ensure NUL-termination even on overflow
530 /** Set a given Options* as "current" just for a particular scope. */
532 CVC4_THREADLOCAL_TYPE(Options
*)* d_field
;
535 OptionsGuard(CVC4_THREADLOCAL_TYPE(Options
*)* field
, Options
* opts
) :
543 };/* class OptionsGuard */
545 }/* CVC4::options namespace */
548 * Parse argc/argv and put the result into a CVC4::Options.
549 * The return value is what's left of the command line (that is, the
550 * non-option arguments).
552 std::vector
<std::string
> Options::parseOptions(int argc
, char* main_argv
[]) throw(OptionException
) {
553 options::OptionsGuard
guard(&s_current
, this);
555 // Having this synonym simplifies the generation code in mkoptions.
556 options::OptionsHandler
* handler
= d_handler
;
558 const char *progName
= main_argv
[0];
560 ArgumentExtender
argumentExtender(s_preemptAdditional
, s_maxoptlen
);
561 std::vector
<char*> allocated
;
563 Debug("options") << "main_argv == " << main_argv
<< std::endl
;
565 // Reset getopt(), in the case of multiple calls to parseOptions().
566 // This can be = 1 in newer GNU getopt, but older (< 2007) require = 0.
568 #if HAVE_DECL_OPTRESET
569 optreset
= 1; // on BSD getopt() (e.g. Mac OS), might need this
570 #endif /* HAVE_DECL_OPTRESET */
572 // find the base name of the program
573 const char *x
= strrchr(progName
, '/');
577 d_holder
->binary_name
= std::string(progName
);
580 char **extra_argv
= (char**) malloc(2 * sizeof(char*));
581 extra_argv
[0] = NULL
;
582 extra_argv
[1] = NULL
;
584 int extra_optind
= 0, main_optind
= 0;
586 int *optind_ref
= &main_optind
;
588 char** argv
= main_argv
;
590 std::vector
<std::string
> nonOptions
;
595 std::string option
, optionarg
;
596 Debug("preemptGetopt") << "top of loop, extra_optind == " << extra_optind
597 << ", extra_argc == " << extra_argc
<< std::endl
;
598 if((extra_optind
== 0 ? 1 : extra_optind
) < extra_argc
) {
599 #if HAVE_DECL_OPTRESET
600 if(optind_ref
!= &extra_optind
) {
601 optreset
= 1; // on BSD getopt() (e.g. Mac OS), might need this
603 #endif /* HAVE_DECL_OPTRESET */
604 old_optind
= optind
= extra_optind
;
605 optind_ref
= &extra_optind
;
607 Debug("preemptGetopt") << "in preempt code, next arg is "
608 << extra_argv
[optind
== 0 ? 1 : optind
]
610 if(extra_argv
[extra_optind
== 0 ? 1 : extra_optind
][0] != '-') {
612 "preempted args cannot give non-options command-line args (found `%s')",
613 extra_argv
[extra_optind
== 0 ? 1 : extra_optind
]);
615 c
= getopt_long(extra_argc
, extra_argv
,
616 "+:${all_modules_short_options}",
617 cmdlineOptions
, NULL
);
618 Debug("preemptGetopt") << "in preempt code"
619 << ", c == " << c
<< " (`" << char(c
) << "')"
620 << " optind == " << optind
<< std::endl
;
622 ( optopt
>= $
{long_option_value_begin
} && optopt
<= $
{long_option_value_end
} )) {
624 option
= argv
[old_optind
== 0 ? 1 : old_optind
];
625 optionarg
= (optarg
== NULL
) ? "" : optarg
;
628 option
= std::string("-") + char(optopt
);
629 optionarg
= (optarg
== NULL
) ? "" : optarg
;
631 if(optind
>= extra_argc
) {
632 Debug("preemptGetopt") << "-- no more preempt args" << std::endl
;
634 while(extra_argv
[i
] != NULL
&& extra_argv
[i
][0] != '\0') {
635 extra_argv
[i
][0] = '\0';
641 Debug("preemptGetopt") << "-- more preempt args" << std::endl
;
642 extra_optind
= optind
;
646 #if HAVE_DECL_OPTRESET
647 if(optind_ref
!= &main_optind
) {
648 optreset
= 1; // on BSD getopt() (e.g. Mac OS), might need this
650 #endif /* HAVE_DECL_OPTRESET */
651 old_optind
= optind
= main_optind
;
652 optind_ref
= &main_optind
;
654 if(main_optind
< argc
&& main_argv
[main_optind
][0] != '-') {
656 if(main_optind
!= 0) {
657 nonOptions
.push_back(main_argv
[main_optind
]);
660 } while(main_optind
< argc
&& main_argv
[main_optind
][0] != '-');
663 Debug("options") << "[ before, optind == " << optind
<< " ]" << std::endl
;
664 #if defined(__MINGW32__) || defined(__MINGW64__)
665 if(optreset
== 1 && optind
> 1) {
666 // on mingw, optreset will reset the optind, so we have to
667 // manually advance argc, argv
668 main_argv
[optind
- 1] = main_argv
[0];
669 argv
= main_argv
+= optind
- 1;
671 old_optind
= optind
= main_optind
= 1;
673 Debug("options") << "looking at : " << argv
[0] << std::endl
;
675 /*c = getopt_long(argc, main_argv,
676 "+:${all_modules_short_options}",
677 cmdlineOptions, NULL);
678 Debug("options") << "pre-emptory c is " << c << " (" << char(c) << ")" << std::endl;
679 Debug("options") << "optind was reset to " << optind << std::endl;
680 optind = main_optind;
681 Debug("options") << "I restored optind to " << optind << std::endl;*/
683 #endif /* __MINGW32__ || __MINGW64__ */
684 Debug("options") << "[ argc == " << argc
685 << ", main_argv == " << main_argv
<< " ]" << std::endl
;
686 c
= getopt_long(argc
, main_argv
,
687 "+:${all_modules_short_options}",
688 cmdlineOptions
, NULL
);
689 main_optind
= optind
;
690 Debug("options") << "[ got " << int(c
) << " (" << char(c
) << ") ]"
692 Debug("options") << "[ next option will be at pos: " << optind
<< " ]"
695 Debug("options") << "done with option parsing" << std::endl
;
698 option
= argv
[old_optind
== 0 ? 1 : old_optind
];
699 optionarg
= (optarg
== NULL
) ? "" : optarg
;
702 Debug("preemptGetopt") << "processing option " << c
703 << " (`" << char(c
) << "'), " << option
<< std::endl
;
706 $
{all_modules_option_handlers
}
708 #line 709 "${template}"
711 // This can be a long or short option, and the way to get at the
712 // name of it is different.
713 throw OptionException(std::string("option `") + option
+ "' missing its required argument");
717 if( ( optopt
== 0 || ( optopt
>= $
{long_option_value_begin
} && optopt
<= $
{long_option_value_end
} ) ) &&
718 !strncmp(argv
[optind
- 1], "--thread", 8) &&
719 strlen(argv
[optind
- 1]) > 8 ) {
720 if(! isdigit(argv
[optind
- 1][8])) {
721 throw OptionException(formatThreadOptionException(option
));
723 std::vector
<std::string
>& threadArgv
= d_holder
->threadArgv
;
725 long tnum
= strtol(argv
[optind
- 1] + 8, &end
, 10);
726 if(tnum
< 0 || (*end
!= '\0' && *end
!= '=')) {
727 throw OptionException(formatThreadOptionException(option
));
729 if(threadArgv
.size() <= size_t(tnum
)) {
730 threadArgv
.resize(tnum
+ 1);
732 if(threadArgv
[tnum
] != "") {
733 threadArgv
[tnum
] += " ";
735 if(*end
== '\0') { // e.g., we have --thread0 "foo"
737 throw OptionException(std::string("option `") + option
738 + "' missing its required argument");
740 Debug("options") << "thread " << tnum
<< " gets option "
741 << argv
[optind
] << std::endl
;
742 threadArgv
[tnum
] += argv
[(*optind_ref
)++];
743 } else { // e.g., we have --thread0="foo"
745 throw OptionException(std::string("option `") + option
+
746 "' missing its required argument");
748 Debug("options") << "thread " << tnum
<< " gets option " << (end
+ 1)
750 threadArgv
[tnum
] += end
+ 1;
752 Debug("options") << "thread " << tnum
<< " now has " << threadArgv
[tnum
]
757 throw OptionException(std::string("can't understand option `") + option
+
758 "'" + suggestCommandLineOptions(option
));
762 Debug("options") << "returning " << nonOptions
.size() << " non-option arguments." << std::endl
;
765 for(std::vector
<char*>::iterator i
= allocated
.begin(), iend
= allocated
.end();
769 #warning "TODO: Unit tests fail if garbage collection is done here."
777 std::string
Options::suggestCommandLineOptions(const std::string
& optionName
) throw() {
778 DidYouMean didYouMean
;
781 for(size_t i
= 0; (opt
= cmdlineOptions
[i
].name
) != NULL
; ++i
) {
782 didYouMean
.addWord(std::string("--") + cmdlineOptions
[i
].name
);
785 return didYouMean
.getMatchAsString(optionName
.substr(0, optionName
.find('=')));
788 static const char* smtOptions
[] = {
789 $
{all_modules_smt_options
},
790 #line 790 "${template}"
794 std::vector
<std::string
> Options::suggestSmtOptions(const std::string
& optionName
) throw() {
795 std::vector
<std::string
> suggestions
;
798 for(size_t i
= 0; (opt
= smtOptions
[i
]) != NULL
; ++i
) {
799 if(std::strstr(opt
, optionName
.c_str()) != NULL
) {
800 suggestions
.push_back(opt
);
807 std::vector
< std::vector
<std::string
> > Options::getOptions() const throw() {
808 std::vector
< std::vector
<std::string
> > opts
;
810 $
{all_modules_get_options
}
812 #line 813 "${template}"
818 #undef USE_EARLY_TYPE_CHECKING_BY_DEFAULT
819 #undef DO_SEMANTIC_CHECKS_BY_DEFAULT
821 }/* CVC4 namespace */