Use references instead of getter functions (#6597)
[cvc5.git] / src / options / options_template.cpp
index 9de47b388d893339330f97c9ee2793e0d7a77322..26e11a6701f34fb2dc3291d97509a9ba3ad3dd5d 100644 (file)
@@ -1,26 +1,25 @@
-/*********************                                                        */
-/*! \file options_template.cpp
- ** \verbatim
- ** Top contributors (to current version):
- **   Tim King, Morgan Deters, Kshitij Bansal
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief Contains code for handling command-line options.
- **
- ** Contains code for handling command-line options
- **/
+/******************************************************************************
+ * Top contributors (to current version):
+ *   Morgan Deters, Tim King, Andrew Reynolds
+ *
+ * This file is part of the cvc5 project.
+ *
+ * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+ * in the top-level source directory and their institutional affiliations.
+ * All rights reserved.  See the file COPYING in the top-level source
+ * directory for licensing information.
+ * ****************************************************************************
+ *
+ * Contains code for handling command-line options.
+ */
 
 #if !defined(_BSD_SOURCE) && defined(__MINGW32__) && !defined(__MINGW64__)
 // force use of optreset; mingw32 croaks on argv-switching otherwise
-#  include "cvc4autoconfig.h"
-#  define _BSD_SOURCE
-#  undef HAVE_DECL_OPTRESET
-#  define HAVE_DECL_OPTRESET 1
-#  define CVC4_IS_NOT_REALLY_BSD
+#include "base/cvc5config.h"
+#define _BSD_SOURCE
+#undef HAVE_DECL_OPTRESET
+#define HAVE_DECL_OPTRESET 1
+#define CVC5_IS_NOT_REALLY_BSD
 #endif /* !_BSD_SOURCE && __MINGW32__ && !__MINGW64__ */
 
 #ifdef __MINGW64__
@@ -30,13 +29,12 @@ extern int optreset;
 #include <getopt.h>
 
 // clean up
-#ifdef CVC4_IS_NOT_REALLY_BSD
+#ifdef CVC5_IS_NOT_REALLY_BSD
 #  undef _BSD_SOURCE
-#endif /* CVC4_IS_NOT_REALLY_BSD */
+#endif /* CVC5_IS_NOT_REALLY_BSD */
 
 #include <unistd.h>
 #include <string.h>
-#include <stdint.h>
 #include <time.h>
 
 #include <cstdio>
@@ -48,36 +46,29 @@ extern int optreset;
 #include <sstream>
 #include <limits>
 
-#include "base/tls.h"
-#include "base/cvc4_assert.h"
+#include "base/check.h"
 #include "base/exception.h"
 #include "base/output.h"
-#include "options/argument_extender.h"
-#include "options/argument_extender_implementation.h"
 #include "options/didyoumean.h"
 #include "options/language.h"
 #include "options/options_handler.h"
+#include "options/options_listener.h"
 
-${include_all_option_headers}
+// clang-format off
+${headers_module}$
 
-#line 64 "${template}"
-
-#include "options/options_holder.h"
-#include "cvc4autoconfig.h"
+#include "base/cvc5config.h"
 #include "options/base_handlers.h"
 
-${option_handler_includes}
-
-#line 72 "${template}"
-
-using namespace CVC4;
-using namespace CVC4::options;
-
-namespace CVC4 {
+${headers_handler}$
 
-CVC4_THREAD_LOCAL Options* Options::s_current = NULL;
+using namespace cvc5;
+using namespace cvc5::options;
+// clang-format on
 
+namespace cvc5 {
 
+thread_local Options* Options::s_current = NULL;
 
 /**
  * This is a default handler for options of built-in C++ type.  This
@@ -115,7 +106,7 @@ struct OptionHandler<T, true, true> {
 
       if(!success){
         throw OptionException(option + ": failed to parse "+ optionarg +
-                              " as an integer of the appropraite type.");
+                              " as an integer of the appropriate type.");
       }
 
       // Depending in the platform unsigned numbers with '-' signs may parse.
@@ -230,27 +221,24 @@ void runBoolPredicates(T, std::string option, bool b, options::OptionsHandler* h
   // that can throw exceptions.
 }
 
-
-Options::Options()
-    : d_holder(new options::OptionsHolder())
-    , d_handler(new options::OptionsHandler(this))
-    , d_forceLogicListeners()
-    , d_beforeSearchListeners()
-    , d_tlimitListeners()
-    , d_tlimitPerListeners()
-    , d_rlimitListeners()
-    , d_rlimitPerListeners()
+Options::Options(OptionsListener* ol)
+    : d_handler(new options::OptionsHandler(this)),
+// clang-format off
+${holder_mem_inits}$
+${holder_ref_inits}$
+// clang-format on
+      d_olisten(ol)
 {}
 
 Options::~Options() {
   delete d_handler;
-  delete d_holder;
 }
 
 void Options::copyValues(const Options& options){
   if(this != &options) {
-    delete d_holder;
-    d_holder = new options::OptionsHolder(*options.d_holder);
+// clang-format off
+${holder_mem_copy}$
+// clang-format on
   }
 }
 
@@ -262,193 +250,47 @@ std::string Options::formatThreadOptionException(const std::string& option) {
   return ss.str();
 }
 
-ListenerCollection::Registration* Options::registerAndNotify(
-    ListenerCollection& collection, Listener* listener, bool notify)
-{
-  ListenerCollection::Registration* registration =
-      collection.registerListener(listener);
-  if(notify) {
-    listener->notify();
-  }
-  return registration;
-}
-
-ListenerCollection::Registration* Options::registerForceLogicListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::forceLogicString);
-  return registerAndNotify(d_forceLogicListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerBeforeSearchListener(
-   Listener* listener)
-{
-  return d_beforeSearchListeners.registerListener(listener);
-}
-
-ListenerCollection::Registration* Options::registerTlimitListener(
-   Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet &&
-      wasSetByUser(options::cumulativeMillisecondLimit);
-  return registerAndNotify(d_tlimitListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerTlimitPerListener(
-   Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::perCallMillisecondLimit);
-  return registerAndNotify(d_tlimitPerListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerRlimitListener(
-   Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::cumulativeResourceLimit);
-  return registerAndNotify(d_rlimitListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerRlimitPerListener(
-   Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::perCallResourceLimit);
-  return registerAndNotify(d_rlimitPerListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerUseTheoryListListener(
-   Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::useTheoryList);
-  return registerAndNotify(d_useTheoryListListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerSetDefaultExprDepthListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::defaultExprDepth);
-  return registerAndNotify(d_setDefaultExprDepthListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerSetDefaultExprDagListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::defaultDagThresh);
-  return registerAndNotify(d_setDefaultDagThreshListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerSetPrintExprTypesListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::printExprTypes);
-  return registerAndNotify(d_setPrintExprTypesListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerSetDumpModeListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::dumpModeString);
-  return registerAndNotify(d_setDumpModeListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerSetPrintSuccessListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::printSuccess);
-  return registerAndNotify(d_setPrintSuccessListeners, listener, notify);
-}
-
-ListenerCollection::Registration* Options::registerDumpToFileNameListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::dumpToFileName);
-  return registerAndNotify(d_dumpToFileListeners, listener, notify);
-}
-
-ListenerCollection::Registration*
-Options::registerSetRegularOutputChannelListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::regularChannelName);
-  return registerAndNotify(d_setRegularChannelListeners, listener, notify);
-}
-
-ListenerCollection::Registration*
-Options::registerSetDiagnosticOutputChannelListener(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::diagnosticChannelName);
-  return registerAndNotify(d_setDiagnosticChannelListeners, listener, notify);
-}
-
-ListenerCollection::Registration*
-Options::registerSetReplayLogFilename(
-    Listener* listener, bool notifyIfSet)
-{
-  bool notify = notifyIfSet && wasSetByUser(options::replayLogFilename);
-  return registerAndNotify(d_setReplayFilenameListeners, listener, notify);
-}
-
-${all_custom_handlers}
-
-#line 394 "${template}"
-
-#ifdef CVC4_DEBUG
-#  define USE_EARLY_TYPE_CHECKING_BY_DEFAULT true
-#else /* CVC4_DEBUG */
-#  define USE_EARLY_TYPE_CHECKING_BY_DEFAULT false
-#endif /* CVC4_DEBUG */
-
-#if defined(CVC4_MUZZLED) || defined(CVC4_COMPETITION_MODE)
-#  define DO_SEMANTIC_CHECKS_BY_DEFAULT false
-#else /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
-#  define DO_SEMANTIC_CHECKS_BY_DEFAULT true
-#endif /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */
-
-options::OptionsHolder::OptionsHolder() : ${all_modules_defaults}
-{
-}
-
-#line 412 "${template}"
-
-static const std::string mostCommonOptionsDescription = "\
-Most commonly-used CVC4 options:${common_documentation}";
+void Options::setListener(OptionsListener* ol) { d_olisten = ol; }
 
-#line 417 "${template}"
+// clang-format off
+${custom_handlers}$
+// clang-format on
 
-static const std::string optionsDescription = mostCommonOptionsDescription + "\n\
-\n\
-Additional CVC4 options:${remaining_documentation}";
+static const std::string mostCommonOptionsDescription =
+    "\
+Most commonly-used cvc5 options:\n"
+    // clang-format off
+${help_common}$
+    // clang-format on
+    ;
 
-#line 423 "${template}"
+// clang-format off
+static const std::string optionsDescription =
+    mostCommonOptionsDescription + "\n\nAdditional cvc5 options:\n"
+${help_others}$;
+// clang-format on
 
 static const std::string optionsFootnote = "\n\
 [*] Each of these options has a --no-OPTIONNAME variant, which reverses the\n\
     sense of the option.\n\
 ";
 
-static const std::string languageDescription = "\
+static const std::string languageDescription =
+    "\
 Languages currently supported as arguments to the -L / --lang option:\n\
   auto                           attempt to automatically determine language\n\
-  cvc4 | presentation | pl       CVC4 presentation language\n\
-  smt1 | smtlib1                 SMT-LIB format 1.2\n\
+  cvc | presentation | pl        CVC presentation language\n\
   smt | smtlib | smt2 |\n\
-  smt2.0 | smtlib2 | smtlib2.0   SMT-LIB format 2.0\n\
-  smt2.5 | smtlib2.5             SMT-LIB format 2.5\n\
-  smt2.6 | smtlib2.6             SMT-LIB format 2.6\n\
-  tptp                           TPTP format (cnf and fof)\n\
-  sygus                          SyGuS format\n\
+  smt2.6 | smtlib2.6             SMT-LIB format 2.6 with support for the strings standard\n\
+  tptp                           TPTP format (cnf, fof and tff)\n\
+  sygus | sygus2                 SyGuS version 2.0\n\
 \n\
 Languages currently supported as arguments to the --output-lang option:\n\
   auto                           match output language to input language\n\
-  cvc4 | presentation | pl       CVC4 presentation language\n\
-  cvc3                           CVC3 presentation language\n\
-  smt1 | smtlib1                 SMT-LIB format 1.2\n\
+  cvc | presentation | pl        CVC presentation language\n\
   smt | smtlib | smt2 |\n\
-  smt2.0 | smtlib2.0 | smtlib2   SMT-LIB format 2.0\n\
-  smt2.5 | smtlib2.5             SMT-LIB format 2.5\n\
-  smt2.6 | smtlib2.6             SMT-LIB format 2.6\n\
+  smt2.6 | smtlib2.6             SMT-LIB format 2.6 with support for the strings standard\n\
   tptp                           TPTP format\n\
-  z3str                          SMT-LIB 2.0 with Z3-str string constraints\n\
   ast                            internal format (simple syntax trees)\n\
 ";
 
@@ -496,37 +338,11 @@ void Options::printLanguageHelp(std::ostream& out) {
  * If you add something that has a short option equivalent, you should
  * add it to the getopt_long() call in parseOptions().
  */
-static struct option cmdlineOptions[] = {${all_modules_long_options}
-  { NULL, no_argument, NULL, '\0' }
-};/* cmdlineOptions */
-
-#line 504 "${template}"
-
-// static void preemptGetopt(int& argc, char**& argv, const char* opt) {
-
-//   Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl;
-
-//   AlwaysAssert(opt != NULL && *opt != '\0');
-//   AlwaysAssert(strlen(opt) <= maxoptlen);
-
-//   ++argc;
-//   unsigned i = 1;
-//   while(argv[i] != NULL && argv[i][0] != '\0') {
-//     ++i;
-//   }
-
-//   if(argv[i] == NULL) {
-//     argv = (char**) realloc(argv, (i + 6) * sizeof(char*));
-//     for(unsigned j = i; j < i + 5; ++j) {
-//       argv[j] = (char*) malloc(sizeof(char) * maxoptlen);
-//       argv[j][0] = '\0';
-//     }
-//     argv[i + 5] = NULL;
-//   }
-
-//   strncpy(argv[i], opt, maxoptlen - 1);
-//   argv[i][maxoptlen - 1] = '\0'; // ensure NUL-termination even on overflow
-// }
+// clang-format off
+static struct option cmdlineOptions[] = {
+  ${cmdline_options}$
+  {nullptr, no_argument, nullptr, '\0'}};
+// clang-format on
 
 namespace options {
 
@@ -545,17 +361,19 @@ public:
   }
 };/* class OptionsGuard */
 
-}/* CVC4::options namespace */
+}  // namespace options
 
 /**
- * Parse argc/argv and put the result into a CVC4::Options.
+ * Parse argc/argv and put the result into a cvc5::Options.
  * The return value is what's left of the command line (that is, the
  * non-option arguments).
+ *
+ * Throws OptionException on failures.
  */
 std::vector<std::string> Options::parseOptions(Options* options,
-                                               int argc, char* argv[])
-  throw(OptionException) {
-
+                                               int argc,
+                                               char* argv[])
+{
   Assert(options != NULL);
   Assert(argv != NULL);
 
@@ -576,15 +394,10 @@ std::vector<std::string> Options::parseOptions(Options* options,
   if(x != NULL) {
     progName = x + 1;
   }
-  options->d_holder->binary_name = std::string(progName);
-
-  ArgumentExtender* argumentExtender = new ArgumentExtenderImplementation();
-  for(int position = 1; position < argc; position++) {
-    argumentExtender->pushBackArgument(argv[position]);
-  }
+  options->base.binary_name = std::string(progName);
 
   std::vector<std::string> nonoptions;
-  parseOptionsRecursive(options, argumentExtender, &nonoptions);
+  options->parseOptionsRecursive(argc, argv, &nonoptions);
   if(Debug.isOn("options")){
     for(std::vector<std::string>::const_iterator i = nonoptions.begin(),
           iend = nonoptions.end(); i != iend; ++i){
@@ -592,21 +405,25 @@ std::vector<std::string> Options::parseOptions(Options* options,
     }
   }
 
-  delete argumentExtender;
   return nonoptions;
 }
 
-void Options::parseOptionsRecursive(Options* options,
-                                    ArgumentExtender* extender,
-                                    std::vector<std::string>* nonoptions)
-  throw(OptionException) {
+std::string suggestCommandLineOptions(const std::string& optionName)
+{
+  DidYouMean didYouMean;
+
+  const char* opt;
+  for(size_t i = 0; (opt = cmdlineOptions[i].name) != nullptr; ++i) {
+    didYouMean.addWord(std::string("--") + cmdlineOptions[i].name);
+  }
 
-  int argc;
-  char** argv;
+  return didYouMean.getMatchAsString(optionName.substr(0, optionName.find('=')));
+}
 
-  extender->movePreemptionsToArguments();
-  extender->pushFrontArgument("");
-  extender->getArguments(&argc, &argv);
+void Options::parseOptionsRecursive(int argc,
+                                    char* argv[],
+                                    std::vector<std::string>* nonoptions)
+{
 
   if(Debug.isOn("options")) {
     Debug("options") << "starting a new parseOptionsRecursive with "
@@ -617,10 +434,6 @@ void Options::parseOptionsRecursive(Options* options,
     }
   }
 
-  // Having this synonym simplifies the generation code in mkoptions.
-  options::OptionsHandler* handler = options->d_handler;
-  options::OptionsHolder* holder = options->d_holder;
-
   // Reset getopt(), in the case of multiple calls to parseOptions().
   // This can be = 1 in newer GNU getopt, but older (< 2007) require = 0.
   optind = 0;
@@ -628,27 +441,19 @@ void Options::parseOptionsRecursive(Options* options,
   optreset = 1; // on BSD getopt() (e.g. Mac OS), might need this
 #endif /* HAVE_DECL_OPTRESET */
 
-  
+  // We must parse the binary name, which is manually ignored below. Setting
+  // this to 1 leads to incorrect behavior on some platforms.
   int main_optind = 0;
   int old_optind;
 
 
   while(true) { // Repeat Forever
 
-    if(extender->hasPreemptions()){
-      // Stop this round of parsing. We now parse recursively
-      // to start on a new character array for argv.
-      parseOptionsRecursive(options, extender, nonoptions);
-      break;
-    }
-
     optopt = 0;
     std::string option, optionarg;
 
     optind = main_optind;
     old_optind = main_optind;
-    //optind_ref = &main_optind;
-    //argv = main_argv;
 
     // If we encounter an element that is not at zero and does not start
     // with a "-", this is a non-option. We consume this element as a
@@ -659,7 +464,6 @@ void Options::parseOptionsRecursive(Options* options,
                        << " as a non-option." << std::endl;
       nonoptions->push_back(argv[main_optind]);
       ++main_optind;
-      extender->popFrontArgument();
       continue;
     }
 
@@ -669,14 +473,13 @@ void Options::parseOptionsRecursive(Options* options,
     Debug("options") << "[ before, optind == " << optind << " ]" << std::endl;
     Debug("options") << "[ argc == " << argc << ", argv == " << argv << " ]"
                      << std::endl;
+    // clang-format off
     int c = getopt_long(argc, argv,
-                        "+:${all_modules_short_options}",
+                        "+:${options_short}$",
                         cmdlineOptions, NULL);
+    // clang-format on
 
-    while(main_optind < optind) {
-      main_optind++;
-      extender->popFrontArgument();
-    }
+    main_optind = optind;
 
     Debug("options") << "[ got " << int(c) << " (" << char(c) << ") ]"
                      << "[ next option will be at pos: " << optind << " ]"
@@ -685,19 +488,6 @@ void Options::parseOptionsRecursive(Options* options,
     // The initial getopt_long call should always determine that argv[0]
     // is not an option and returns -1. We always manually advance beyond
     // this element.
-    //
-    // We have to reinitialize optind to 0 instead of 1 as we need to support
-    // changing the argv array passed to getopt.
-    // This is needed as are using GNU extensions.
-    // From: http://man7.org/linux/man-pages/man3/getopt.3.html
-    // A program that scans multiple argument vectors, or rescans the same
-    // vector more than once, and wants to make use of GNU extensions such
-    // as '+' and '-' at the start of optstring, or changes the value of
-    //  POSIXLY_CORRECT between scans, must reinitialize getopt() by
-    //  resetting optind to 0, rather than the traditional value of 1.
-    //  (Resetting to 0 forces the invocation of an internal initialization
-    //  routine that rechecks POSIXLY_CORRECT and checks for GNU extensions
-    //  in optstring.)
     if ( old_optind == 0  && c == -1 ) {
       Assert(main_optind > 0);
       continue;
@@ -719,120 +509,72 @@ void Options::parseOptionsRecursive(Options* options,
     Debug("preemptGetopt") << "processing option " << c
                            << " (`" << char(c) << "'), " << option << std::endl;
 
-    switch(c) {
-${all_modules_option_handlers}
-
-#line 726 "${template}"
+    // clang-format off
+    switch(c)
+    {
+${options_handler}$
 
-    case ':':
+      case ':' :
       // This can be a long or short option, and the way to get at the
       // name of it is different.
-      throw OptionException(std::string("option `") + option +
-                            "' missing its required argument");
-
-    case '?':
-    default:
-      if( ( optopt == 0 ||
-            ( optopt >= ${long_option_value_begin} &&
-              optopt <= ${long_option_value_end} )
-          ) && !strncmp(argv[optind - 1], "--thread", 8) &&
-          strlen(argv[optind - 1]) > 8 )
-      {
-        if(! isdigit(argv[optind - 1][8])) {
-          throw OptionException(formatThreadOptionException(option));
-        }
-        std::vector<std::string>& threadArgv = holder->threadArgv;
-        char *end;
-        long tnum = strtol(argv[optind - 1] + 8, &end, 10);
-        if(tnum < 0 || (*end != '\0' && *end != '=')) {
-          throw OptionException(formatThreadOptionException(option));
-        }
-        if(threadArgv.size() <= size_t(tnum)) {
-          threadArgv.resize(tnum + 1);
-        }
-        if(threadArgv[tnum] != "") {
-          threadArgv[tnum] += " ";
-        }
-        if(*end == '\0') { // e.g., we have --thread0 "foo"
-          if(argc <= optind) {
-            throw OptionException(std::string("option `") + option +
-                                  "' missing its required argument");
-          }
-          Debug("options") << "thread " << tnum << " gets option "
-                           << argv[optind] << std::endl;
-          threadArgv[tnum] += argv[main_optind];
-          main_optind++;
-        } else { // e.g., we have --thread0="foo"
-          if(end[1] == '\0') {
-            throw OptionException(std::string("option `") + option +
-                                  "' missing its required argument");
-          }
-          Debug("options") << "thread " << tnum << " gets option "
-                           << (end + 1) << std::endl;
-          threadArgv[tnum] += end + 1;
-        }
-        Debug("options") << "thread " << tnum << " now has "
-                         << threadArgv[tnum] << std::endl;
-        break;
-      }
+      throw OptionException(std::string("option `") + option
+                            + "' missing its required argument");
 
-      throw OptionException(std::string("can't understand option `") + option +
-                            "'" + suggestCommandLineOptions(option));
+      case '?':
+      default:
+        throw OptionException(std::string("can't understand option `") + option
+                              + "'" + suggestCommandLineOptions(option));
     }
   }
+  // clang-format on
 
   Debug("options") << "got " << nonoptions->size()
                    << " non-option arguments." << std::endl;
-
-  free(argv);
 }
 
-std::string Options::suggestCommandLineOptions(const std::string& optionName)
+// clang-format off
+std::vector<std::vector<std::string> > Options::getOptions() const
 {
-  DidYouMean didYouMean;
+  std::vector< std::vector<std::string> > opts;
 
-  const char* opt;
-  for(size_t i = 0; (opt = cmdlineOptions[i].name) != NULL; ++i) {
-    didYouMean.addWord(std::string("--") + cmdlineOptions[i].name);
-  }
+  ${options_getoptions}$
 
-  return didYouMean.getMatchAsString(optionName.substr(0, optionName.find('=')));
+  return opts;
 }
+// clang-format on
 
-static const char* smtOptions[] = {
-  ${all_modules_smt_options},
-#line 804 "${template}"
-  NULL
-};/* smtOptions[] */
-
-std::vector<std::string> Options::suggestSmtOptions(
-    const std::string& optionName)
+void Options::setOption(const std::string& key, const std::string& optionarg)
 {
-  std::vector<std::string> suggestions;
-
-  const char* opt;
-  for(size_t i = 0; (opt = smtOptions[i]) != NULL; ++i) {
-    if(std::strstr(opt, optionName.c_str()) != NULL) {
-      suggestions.push_back(opt);
-    }
+  Trace("options") << "setOption(" << key << ", " << optionarg << ")"
+                   << std::endl;
+  // first update this object
+  setOptionInternal(key, optionarg);
+  // then, notify the provided listener
+  if (d_olisten != nullptr)
+  {
+    d_olisten->notifySetOption(key);
   }
-
-  return suggestions;
 }
 
-std::vector<std::vector<std::string> > Options::getOptions() const
+// clang-format off
+void Options::setOptionInternal(const std::string& key,
+                                const std::string& optionarg)
 {
-  std::vector< std::vector<std::string> > opts;
-
-  ${all_modules_get_options}
+  options::OptionsHandler* handler = d_handler;
+  ${setoption_handlers}$
+  throw UnrecognizedOptionException(key);
+}
+// clang-format on
 
-#line 826 "${template}"
+// clang-format off
+std::string Options::getOption(const std::string& key) const
+{
+  Trace("options") << "Options::getOption(" << key << ")" << std::endl;
+  ${getoption_handlers}$
 
-  return opts;
+  throw UnrecognizedOptionException(key);
 }
+// clang-format on
 
+}  // namespace cvc5
 
-#undef USE_EARLY_TYPE_CHECKING_BY_DEFAULT
-#undef DO_SEMANTIC_CHECKS_BY_DEFAULT
-
-}/* CVC4 namespace */