summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGereon Kremer <nafur42@gmail.com>2021-09-08 11:41:50 -0700
committerGitHub <noreply@github.com>2021-09-08 18:41:50 +0000
commit54148758dba8e3523fa1c746922692d8ad3df6e8 (patch)
treea31527a0baa21da09d2af4b97af9692d416e4c8d
parentd6b3329e3f2b6e29e5f4af6cf09fd32e26c47e15 (diff)
Refactor code generation for options.h/.cpp (#7126)
This PR refactors the options code generation for the options/options.h/.cpp files.
-rw-r--r--src/options/mkoptions.py107
-rw-r--r--src/options/options_template.cpp19
2 files changed, 67 insertions, 59 deletions
diff --git a/src/options/mkoptions.py b/src/options/mkoptions.py
index 55e047047..d50681eb7 100644
--- a/src/options/mkoptions.py
+++ b/src/options/mkoptions.py
@@ -176,41 +176,6 @@ TPL_MODE_HANDLER_CASE = \
}}"""
-def get_module_headers(modules):
- """Render includes for module headers"""
- return concat_format('#include "{header}"', modules)
-
-
-def get_holder_fwd_decls(modules):
- """Render forward declaration of holder structs"""
- return concat_format(' struct Holder{id_cap};', modules)
-
-
-def get_holder_mem_decls(modules):
- """Render declarations of holder members of the Option class"""
- return concat_format(' std::unique_ptr<options::Holder{id_cap}> d_{id};', modules)
-
-
-def get_holder_mem_inits(modules):
- """Render initializations of holder members of the Option class"""
- return concat_format(' d_{id}(std::make_unique<options::Holder{id_cap}>()),', modules)
-
-
-def get_holder_ref_inits(modules):
- """Render initializations of holder references of the Option class"""
- return concat_format(' {id}(*d_{id}),', modules)
-
-
-def get_holder_mem_copy(modules):
- """Render copy operation of holder members of the Option class"""
- return concat_format(' *d_{id} = *options.d_{id};', modules)
-
-
-def get_holder_ref_decls(modules):
- """Render reference declarations for holder members of the Option class"""
- return concat_format(' options::Holder{id_cap}& {id};', modules)
-
-
def get_handler(option):
"""Render handler call for assignment functions"""
optname = option.long_name if option.long else ""
@@ -339,6 +304,56 @@ def generate_get_impl(modules):
return self.long_name if self.long_name else self.name
+################################################################################
+################################################################################
+# code generation functions
+
+################################################################################
+# for options/options.h
+
+
+def generate_holder_fwd_decls(modules):
+ """Render forward declaration of holder structs"""
+ return concat_format(' struct Holder{id_cap};', modules)
+
+
+def generate_holder_mem_decls(modules):
+ """Render declarations of holder members of the Option class"""
+ return concat_format(
+ ' std::unique_ptr<options::Holder{id_cap}> d_{id};', modules)
+
+
+def generate_holder_ref_decls(modules):
+ """Render reference declarations for holder members of the Option class"""
+ return concat_format(' options::Holder{id_cap}& {id};', modules)
+
+
+################################################################################
+# for options/options.cpp
+
+
+def generate_module_headers(modules):
+ """Render includes for module headers"""
+ return concat_format('#include "{header}"', modules)
+
+
+def generate_holder_mem_inits(modules):
+ """Render initializations of holder members of the Option class"""
+ return concat_format(
+ ' d_{id}(std::make_unique<options::Holder{id_cap}>()),',
+ modules)
+
+
+def generate_holder_ref_inits(modules):
+ """Render initializations of holder references of the Option class"""
+ return concat_format(' {id}(*d_{id}),', modules)
+
+
+def generate_holder_mem_copy(modules):
+ """Render copy operation of holder members of the Option class"""
+ return concat_format(' *d_{id} = *options.d_{id};', modules)
+
+
class SphinxGenerator:
def __init__(self):
self.common = []
@@ -745,9 +760,7 @@ def add_getopt_long(long_name, argument_req, getopt_long):
def codegen_all_modules(modules, build_dir, dst_dir, tpls):
- """
- Generate code for all option modules (options.cpp).
- """
+ """Generate code for all option modules."""
headers_module = [] # generated *_options.h header includes
headers_handler = set() # option includes (for handlers, predicates, ...)
@@ -920,18 +933,20 @@ def codegen_all_modules(modules, build_dir, dst_dir, tpls):
options_handler.extend(cases)
data = {
- 'holder_fwd_decls': get_holder_fwd_decls(modules),
- 'holder_mem_decls': get_holder_mem_decls(modules),
- 'holder_ref_decls': get_holder_ref_decls(modules),
- 'headers_module': get_module_headers(modules),
- 'headers_handler': '\n'.join(sorted(list(headers_handler))),
- 'holder_mem_inits': get_holder_mem_inits(modules),
- 'holder_ref_inits': get_holder_ref_inits(modules),
- 'holder_mem_copy': get_holder_mem_copy(modules),
+ # options/options.h
+ 'holder_fwd_decls': generate_holder_fwd_decls(modules),
+ 'holder_mem_decls': generate_holder_mem_decls(modules),
+ 'holder_ref_decls': generate_holder_ref_decls(modules),
+ # options/options.cpp
+ 'headers_module': generate_module_headers(modules),
+ 'holder_mem_inits': generate_holder_mem_inits(modules),
+ 'holder_ref_inits': generate_holder_ref_inits(modules),
+ 'holder_mem_copy': generate_holder_mem_copy(modules),
# options/options_public.cpp
'options_includes': generate_public_includes(modules),
'getnames_impl': generate_getnames_impl(modules),
'get_impl': generate_get_impl(modules),
+ 'headers_handler': '\n'.join(sorted(list(headers_handler))),
'cmdline_options': '\n '.join(getopt_long),
'help_common': '\n'.join(help_common),
'help_others': '\n'.join(help_others),
diff --git a/src/options/options_template.cpp b/src/options/options_template.cpp
index 06a423438..c6f24a41d 100644
--- a/src/options/options_template.cpp
+++ b/src/options/options_template.cpp
@@ -16,21 +16,12 @@
#include "options/options.h"
#include "base/check.h"
-#include "base/exception.h"
-#include "base/output.h"
-#include "options/language.h"
+#include "base/cvc5config.h"
#include "options/options_handler.h"
#include "options/options_listener.h"
// clang-format off
${headers_module}$
-
-#include "base/cvc5config.h"
-
-${headers_handler}$
-
-using namespace cvc5;
-using namespace cvc5::options;
// clang-format on
namespace cvc5
@@ -49,13 +40,15 @@ ${holder_ref_inits}$
Options::~Options() {}
-void Options::copyValues(const Options& options){
- if(this != &options) {
+ void Options::copyValues(const Options& options)
+ {
+ if (this != &options)
+ {
// clang-format off
${holder_mem_copy}$
// clang-format on
+ }
}
-}
} // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback