1 /********************* */
4 ** Top contributors (to current version):
5 ** Tim King, Morgan Deters, Kshitij Bansal
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2016 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 Global (command-line, set-option, ...) parameters for SMT.
14 ** Global (command-line, set-option, ...) parameters for SMT.
17 #include "cvc4_public.h"
19 #ifndef __CVC4__OPTIONS__OPTIONS_H
20 #define __CVC4__OPTIONS__OPTIONS_H
27 #include "base/listener.h"
28 #include "base/modal_exception.h"
30 #include "options/argument_extender.h"
31 #include "options/language.h"
32 #include "options/printer_modes.h"
33 #include "options/option_exception.h"
40 }/* CVC4::options namespace */
42 class CVC4_PUBLIC Options
{
43 /** The struct that holds all option values. */
44 options::OptionsHolder
* d_holder
;
46 /** The handler for the options of the theory. */
47 options::OptionsHandler
* d_handler
;
49 /** The current Options in effect */
50 static CVC4_THREADLOCAL(Options
*) s_current
;
52 /** Listeners for options::forceLogicString being set. */
53 ListenerCollection d_forceLogicListeners
;
55 /** Listeners for notifyBeforeSearch. */
56 ListenerCollection d_beforeSearchListeners
;
58 /** Listeners for options::tlimit. */
59 ListenerCollection d_tlimitListeners
;
61 /** Listeners for options::tlimit-per. */
62 ListenerCollection d_tlimitPerListeners
;
64 /** Listeners for options::rlimit. */
65 ListenerCollection d_rlimitListeners
;
67 /** Listeners for options::tlimit-per. */
68 ListenerCollection d_rlimitPerListeners
;
70 /** Listeners for options::useTheoryList. */
71 ListenerCollection d_useTheoryListListeners
;
73 /** Listeners for options::defaultExprDepth. */
74 ListenerCollection d_setDefaultExprDepthListeners
;
76 /** Listeners for options::defaultDagThresh. */
77 ListenerCollection d_setDefaultDagThreshListeners
;
79 /** Listeners for options::printExprTypes. */
80 ListenerCollection d_setPrintExprTypesListeners
;
82 /** Listeners for options::dumpModeString. */
83 ListenerCollection d_setDumpModeListeners
;
85 /** Listeners for options::printSuccess. */
86 ListenerCollection d_setPrintSuccessListeners
;
88 /** Listeners for options::dumpToFileName. */
89 ListenerCollection d_dumpToFileListeners
;
91 /** Listeners for options::regularChannelName. */
92 ListenerCollection d_setRegularChannelListeners
;
94 /** Listeners for options::diagnosticChannelName. */
95 ListenerCollection d_setDiagnosticChannelListeners
;
97 /** Listeners for options::replayFilename. */
98 ListenerCollection d_setReplayFilenameListeners
;
101 static ListenerCollection::Registration
* registerAndNotify(
102 ListenerCollection
& collection
, Listener
* listener
, bool notify
);
104 /** Low-level assignment function for options */
106 void assign(T
, std::string option
, std::string value
);
107 /** Low-level assignment function for bool-valued options */
109 void assignBool(T
, std::string option
, bool value
);
111 friend class options::OptionsHandler
;
114 * Options cannot be copied as they are given an explicit list of
115 * Listeners to respond to.
117 Options(const Options
& options
) CVC4_UNDEFINED
;
120 * Options cannot be assigned as they are given an explicit list of
121 * Listeners to respond to.
123 Options
& operator=(const Options
& options
) CVC4_UNDEFINED
;
125 static std::string
formatThreadOptionException(const std::string
& option
);
127 static const size_t s_maxoptlen
= 128;
128 static const unsigned s_preemptAdditional
= 6;
131 class CVC4_PUBLIC OptionsScope
{
133 Options
* d_oldOptions
;
135 OptionsScope(Options
* newOptions
) :
136 d_oldOptions(Options::s_current
)
138 Options::s_current
= newOptions
;
141 Options::s_current
= d_oldOptions
;
145 /** Return true if current Options are null */
146 static inline bool isCurrentNull() {
147 return s_current
== NULL
;
150 /** Get the current Options in effect */
151 static inline Options
* current() {
159 * Copies the value of the options stored in OptionsHolder into the current
161 * This does not copy the listeners in the Options object.
163 void copyValues(const Options
& options
);
166 * Set the value of the given option. Use of this default
167 * implementation causes a compile-time error; write-able
168 * options specialize this template with a real implementation.
171 void set(T
, const typename
T::type
&) {
172 // Flag a compile-time error. Write-able options specialize
173 // this template to provide an implementation.
174 T::you_are_trying_to_assign_to_a_read_only_option
;
178 * Set the value of the given option by key.
180 void setOption(const std::string
& key
, const std::string
& optionarg
)
181 throw(OptionException
, ModalException
);
184 /** Get the value of the given option. Const access only. */
186 const typename
T::type
& operator[](T
) const;
189 * Gets the value of the given option by key and returns value as a string.
191 std::string
getOption(const std::string
& key
) const
192 throw(OptionException
);
194 // Get accessor functions.
195 InputLanguage
getInputLanguage() const;
196 InstFormatMode
getInstFormatMode() const;
197 OutputLanguage
getOutputLanguage() const;
198 bool getCheckProofs() const;
199 bool getContinuedExecution() const;
200 bool getDumpInstantiations() const;
201 bool getDumpModels() const;
202 bool getDumpProofs() const;
203 bool getDumpSynth() const;
204 bool getDumpUnsatCores() const;
205 bool getEarlyExit() const;
206 bool getFallbackSequential() const;
207 bool getFilesystemAccess() const;
208 bool getForceNoLimitCpuWhileDump() const;
209 bool getHelp() const;
210 bool getIncrementalParallel() const;
211 bool getIncrementalSolving() const;
212 bool getInteractive() const;
213 bool getInteractivePrompt() const;
214 bool getLanguageHelp() const;
215 bool getMemoryMap() const;
216 bool getParseOnly() const;
217 bool getProduceModels() const;
218 bool getProof() const;
219 bool getSegvSpin() const;
220 bool getSemanticChecks() const;
221 bool getStatistics() const;
222 bool getStatsEveryQuery() const;
223 bool getStatsHideZeros() const;
224 bool getStrictParsing() const;
225 int getTearDownIncremental() const;
226 bool getVersion() const;
227 bool getWaitToJoin() const;
228 const std::string
& getForceLogicString() const;
229 const std::vector
<std::string
>& getThreadArgv() const;
230 int getSharingFilterByLength() const;
231 int getThreadId() const;
232 int getVerbosity() const;
233 std::istream
* getIn() const;
234 std::ostream
* getErr();
235 std::ostream
* getOut();
236 std::ostream
* getOutConst() const; // TODO: Remove this.
237 std::string
getBinaryName() const;
238 std::string
getReplayInputFilename() const;
239 unsigned getParseStep() const;
240 unsigned getThreadStackSize() const;
241 unsigned getThreads() const;
244 // TODO: Document these.
245 void setCeGuidedInst(bool);
246 void setDumpSynth(bool);
247 void setInputLanguage(InputLanguage
);
248 void setInteractive(bool);
249 void setOut(std::ostream
*);
250 void setOutputLanguage(OutputLanguage
);
251 void setSharingFilterByLength(int length
);
252 void setThreadId(int);
254 bool wasSetByUserCeGuidedInst() const;
255 bool wasSetByUserDumpSynth() const;
256 bool wasSetByUserEarlyExit() const;
257 bool wasSetByUserForceLogicString() const;
258 bool wasSetByUserIncrementalSolving() const;
259 bool wasSetByUserInteractive() const;
260 bool wasSetByUserThreadStackSize() const;
261 bool wasSetByUserThreads() const;
263 // Static accessor functions.
264 // TODO: Document these.
265 static int currentGetSharingFilterByLength();
266 static int currentGetThreadId();
267 static std::ostream
* currentGetOut();
270 * Returns true iff the value of the given option was set
271 * by the user via a command-line option or SmtEngine::setOption().
272 * (Options::set() is low-level and doesn't count.) Returns false
276 bool wasSetByUser(T
) const;
279 * Get a description of the command-line flags accepted by
280 * parseOptions. The returned string will be escaped so that it is
281 * suitable as an argument to printf. */
282 std::string
getDescription() const;
285 * Print overall command-line option usage message, prefixed by
286 * "msg"---which could be an error message causing the usage
287 * output in the first place, e.g. "no such option --foo"
289 static void printUsage(const std::string msg
, std::ostream
& out
);
292 * Print command-line option usage message for only the most-commonly
293 * used options. The message is prefixed by "msg"---which could be
294 * an error message causing the usage output in the first place, e.g.
295 * "no such option --foo"
297 static void printShortUsage(const std::string msg
, std::ostream
& out
);
299 /** Print help for the --lang command line option */
300 static void printLanguageHelp(std::ostream
& out
);
303 * Look up long command-line option names that bear some similarity
304 * to the given name. Returns an empty string if there are no
307 static std::string
suggestCommandLineOptions(const std::string
& optionName
) throw();
310 * Look up SMT option names that bear some similarity to
311 * the given name. Don't include the initial ":". This might be
312 * useful in case of typos. Can return an empty vector if there are
315 static std::vector
<std::string
> suggestSmtOptions(const std::string
& optionName
) throw();
318 * Initialize the Options object options based on the given
319 * command-line arguments given in argc and argv. The return value
320 * is what's left of the command line (that is, the non-option
323 * This function uses getopt_long() and is not thread safe.
325 * Preconditions: options and argv must be non-null.
327 static std::vector
<std::string
> parseOptions(Options
* options
,
328 int argc
, char* argv
[])
329 throw(OptionException
);
332 * Get the setting for all options.
334 std::vector
< std::vector
<std::string
> > getOptions() const throw();
338 * Registers a listener for the notification, notifyBeforeSearch.
340 * The memory for the Registration is controlled by the user and must
341 * be destroyed before the Options object is.
343 * This has multiple usages so having a notifyIfSet flag does not add
344 * clarity. Users should check the relevant flags before registering this.
346 ListenerCollection::Registration
* registerBeforeSearchListener(
351 * Registers a listener for options::forceLogic being set.
353 * If notifyIfSet is true, this calls notify on the listener
354 * if the option was set by the user.
356 * The memory for the Registration is controlled by the user and must
357 * be destroyed before the Options object is.
359 ListenerCollection::Registration
* registerForceLogicListener(
360 Listener
* listener
, bool notifyIfSet
);
363 * Registers a listener for options::tlimit being set.
365 * If notifyIfSet is true, this calls notify on the listener
366 * if the option was set by the user.
368 * The memory for the Registration is controlled by the user and must
369 * be destroyed before the Options object is.
371 ListenerCollection::Registration
* registerTlimitListener(
372 Listener
* listener
, bool notifyIfSet
);
375 * Registers a listener for options::tlimit-per being set.
377 * If notifyIfSet is true, this calls notify on the listener
378 * if the option was set by the user.
380 * The memory for the Registration is controlled by the user and must
381 * be destroyed before the Options object is.
383 ListenerCollection::Registration
* registerTlimitPerListener(
384 Listener
* listener
, bool notifyIfSet
);
388 * Registers a listener for options::rlimit being set.
390 * If notifyIfSet is true, this calls notify on the listener
391 * if the option was set by the user.
393 * The memory for the Registration is controlled by the user and must
394 * be destroyed before the Options object is.
396 ListenerCollection::Registration
* registerRlimitListener(
397 Listener
* listener
, bool notifyIfSet
);
400 * Registers a listener for options::rlimit-per being set.
402 * If notifyIfSet is true, this calls notify on the listener
403 * if the option was set by the user.
405 * The memory for the Registration is controlled by the user and must
406 * be destroyed before the Options object is.
408 ListenerCollection::Registration
* registerRlimitPerListener(
409 Listener
* listener
, bool notifyIfSet
);
412 * Registers a listener for options::useTheoryList being set.
414 * If notifyIfSet is true, this calls notify on the listener
415 * if the option was set by the user.
417 * The memory for the Registration is controlled by the user and must
418 * be destroyed before the Options object is.
420 ListenerCollection::Registration
* registerUseTheoryListListener(
421 Listener
* listener
, bool notifyIfSet
);
425 * Registers a listener for options::defaultExprDepth being set.
427 * If notifyIfSet is true, this calls notify on the listener
428 * if the option was set by the user.
430 * The memory for the Registration is controlled by the user and must
431 * be destroyed before the Options object is.
433 ListenerCollection::Registration
* registerSetDefaultExprDepthListener(
434 Listener
* listener
, bool notifyIfSet
);
437 * Registers a listener for options::defaultDagThresh being set.
439 * If notifyIfSet is true, this calls notify on the listener
440 * if the option was set by the user.
442 * The memory for the Registration is controlled by the user and must
443 * be destroyed before the Options object is.
445 ListenerCollection::Registration
* registerSetDefaultExprDagListener(
446 Listener
* listener
, bool notifyIfSet
);
449 * Registers a listener for options::printExprTypes being set.
451 * If notifyIfSet is true, this calls notify on the listener
452 * if the option was set by the user.
454 * The memory for the Registration is controlled by the user and must
455 * be destroyed before the Options object is.
457 ListenerCollection::Registration
* registerSetPrintExprTypesListener(
458 Listener
* listener
, bool notifyIfSet
);
461 * Registers a listener for options::dumpModeString being set.
463 * If notifyIfSet is true, this calls notify on the listener
464 * if the option was set by the user.
466 * The memory for the Registration is controlled by the user and must
467 * be destroyed before the Options object is.
469 ListenerCollection::Registration
* registerSetDumpModeListener(
470 Listener
* listener
, bool notifyIfSet
);
473 * Registers a listener for options::printSuccess being set.
475 * If notifyIfSet is true, this calls notify on the listener
476 * if the option was set by the user.
478 * The memory for the Registration is controlled by the user and must
479 * be destroyed before the Options object is.
481 ListenerCollection::Registration
* registerSetPrintSuccessListener(
482 Listener
* listener
, bool notifyIfSet
);
485 * Registers a listener for options::dumpToFileName being set.
487 * If notifyIfSet is true, this calls notify on the listener
488 * if the option was set by the user.
490 * The memory for the Registration is controlled by the user and must
491 * be destroyed before the Options object is.
493 ListenerCollection::Registration
* registerDumpToFileNameListener(
494 Listener
* listener
, bool notifyIfSet
);
497 * Registers a listener for options::regularChannelName being set.
499 * If notifyIfSet is true, this calls notify on the listener
500 * if the option was set by the user.
502 * The memory for the Registration is controlled by the user and must
503 * be destroyed before the Options object is.
505 ListenerCollection::Registration
* registerSetRegularOutputChannelListener(
506 Listener
* listener
, bool notifyIfSet
);
509 * Registers a listener for options::diagnosticChannelName being set.
511 * If notifyIfSet is true, this calls notify on the listener
512 * if the option was set by the user.
514 * The memory for the Registration is controlled by the user and must
515 * be destroyed before the Options object is.
517 ListenerCollection::Registration
* registerSetDiagnosticOutputChannelListener(
518 Listener
* listener
, bool notifyIfSet
);
521 * Registers a listener for options::replayLogFilename being set.
523 * If notifyIfSet is true, this calls notify on the listener
524 * if the option was set by the user.
526 * The memory for the Registration is controlled by the user and must
527 * be destroyed before the Options object is.
529 ListenerCollection::Registration
* registerSetReplayLogFilename(
530 Listener
* listener
, bool notifyIfSet
);
532 /** Sends a std::flush to getErr(). */
535 /** Sends a std::flush to getOut(). */
541 * Internal procedure for implementing the parseOptions function.
542 * Initializes the options object based on the given command-line
543 * arguments. This uses an ArgumentExtender containing the
544 * command-line arguments. Nonoptions are stored into nonoptions.
546 * This is not thread safe.
548 * Preconditions: options, extender and nonoptions are non-null.
550 static void parseOptionsRecursive(Options
* options
,
551 options::ArgumentExtender
* extender
,
552 std::vector
<std::string
>* nonoptions
)
553 throw(OptionException
);
554 };/* class Options */
556 }/* CVC4 namespace */
558 #endif /* __CVC4__OPTIONS__OPTIONS_H */