diff --git a/src/codegen/codegen_acc_visitor.hpp b/src/codegen/codegen_acc_visitor.hpp index 80bcba9d68..959b00aeb0 100644 --- a/src/codegen/codegen_acc_visitor.hpp +++ b/src/codegen/codegen_acc_visitor.hpp @@ -28,7 +28,11 @@ namespace codegen { * \brief %Visitor for printing C++ code with OpenACC backend */ class CodegenAccVisitor: public CodegenCoreneuronCppVisitor { + public: + using CodegenCoreneuronCppVisitor::CodegenCoreneuronCppVisitor; + protected: + /// name of the code generation backend std::string backend_name() const override; @@ -133,20 +137,6 @@ class CodegenAccVisitor: public CodegenCoreneuronCppVisitor { /// Replace default implementation by a no-op /// since the buffer cannot be grown up during gpu execution void print_net_send_buffering_grow() override; - - - public: - CodegenAccVisitor(const std::string& mod_file, - const std::string& output_dir, - const std::string& float_type, - bool optimize_ionvar_copies) - : CodegenCoreneuronCppVisitor(mod_file, output_dir, float_type, optimize_ionvar_copies) {} - - CodegenAccVisitor(const std::string& mod_file, - std::ostream& stream, - const std::string& float_type, - bool optimize_ionvar_copies) - : CodegenCoreneuronCppVisitor(mod_file, stream, float_type, optimize_ionvar_copies) {} }; /** \} */ // end of codegen_backends diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.hpp b/src/codegen/codegen_coreneuron_cpp_visitor.hpp index 9c43a4cbe0..43d2b45e87 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.hpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.hpp @@ -60,6 +60,9 @@ using printer::CodePrinter; * have removed return from verbatim block. */ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor { + public: + using CodegenCppVisitor::CodegenCppVisitor; + protected: /****************************************************************************************/ /* Member variables */ @@ -1098,51 +1101,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor { public: - /** - * \brief Constructs the C++ code generator visitor - * - * This constructor instantiates an NMODL C++ code generator and allows writing generated code - * directly to a file in \c [output_dir]/[mod_filename].cpp. - * - * \note No code generation is performed at this stage. Since the code - * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c - * visit_program in order to generate the C++ code corresponding to the AST. - * - * \param mod_filename The name of the model for which code should be generated. - * It is used for constructing an output filename. - * \param output_dir The directory where target C++ file should be generated. - * \param float_type The float type to use in the generated code. The string will be used - * as-is in the target code. This defaults to \c double. - */ - CodegenCoreneuronCppVisitor(std::string mod_filename, - const std::string& output_dir, - std::string float_type, - const bool optimize_ionvar_copies) - : CodegenCppVisitor(mod_filename, output_dir, float_type, optimize_ionvar_copies) {} - - /** - * \copybrief nmodl::codegen::CodegenCoreneuronCppVisitor - * - * This constructor instantiates an NMODL C++ code generator and allows writing generated code - * into an output stream. - * - * \note No code generation is performed at this stage. Since the code - * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c - * visit_program in order to generate the C++ code corresponding to the AST. - * - * \param mod_filename The name of the model for which code should be generated. - * It is used for constructing an output filename. - * \param stream The output stream onto which to write the generated code - * \param float_type The float type to use in the generated code. The string will be used - * as-is in the target code. This defaults to \c double. - */ - CodegenCoreneuronCppVisitor(std::string mod_filename, - std::ostream& stream, - std::string float_type, - const bool optimize_ionvar_copies) - : CodegenCppVisitor(mod_filename, stream, float_type, optimize_ionvar_copies) {} - - /****************************************************************************************/ /* Public printing routines for code generation for use in unit tests */ /****************************************************************************************/ diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index b3d5511da3..e089e9b6b9 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -178,6 +178,59 @@ using printer::CodePrinter; * have removed return from verbatim block. */ class CodegenCppVisitor: public visitor::ConstAstVisitor { + public: + /** + * \brief Constructs the C++ code generator visitor + * + * This constructor instantiates an NMODL C++ code generator and allows writing generated code + * directly to a file in \c [output_dir]/[mod_filename].cpp. + * + * \note No code generation is performed at this stage. Since the code + * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c + * visit_program in order to generate the C++ code corresponding to the AST. + * + * \param mod_filename The name of the model for which code should be generated. + * It is used for constructing an output filename. + * \param output_dir The directory where target C++ file should be generated. + * \param float_type The float type to use in the generated code. The string will be used + * as-is in the target code. This defaults to \c double. + */ + CodegenCppVisitor(std::string mod_filename, + const std::string& output_dir, + std::string float_type, + const bool optimize_ionvar_copies) + : printer(std::make_unique(output_dir + "/" + mod_filename + ".cpp")) + , mod_filename(std::move(mod_filename)) + , float_type(std::move(float_type)) + , optimize_ionvar_copies(optimize_ionvar_copies) {} + + + /** + * \brief Constructs the C++ code generator visitor + * + * This constructor instantiates an NMODL C++ code generator and allows writing generated code + * into an output stream. + * + * \note No code generation is performed at this stage. Since the code + * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c + * visit_program in order to generate the C++ code corresponding to the AST. + * + * \param mod_filename The name of the model for which code should be generated. + * It is used for constructing an output filename. + * \param stream The output stream onto which to write the generated code + * \param float_type The float type to use in the generated code. The string will be used + * as-is in the target code. This defaults to \c double. + */ + CodegenCppVisitor(std::string mod_filename, + std::ostream& stream, + std::string float_type, + const bool optimize_ionvar_copies) + : printer(std::make_unique(stream)) + , mod_filename(std::move(mod_filename)) + , float_type(std::move(float_type)) + , optimize_ionvar_copies(optimize_ionvar_copies) {} + + protected: using SymbolType = std::shared_ptr; @@ -1217,33 +1270,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { void print_nmodl_constants(); - /****************************************************************************************/ - /* Protected constructors */ - /****************************************************************************************/ - - - /// This constructor is private, only the derived classes' public constructors are public - CodegenCppVisitor(std::string mod_filename, - const std::string& output_dir, - std::string float_type, - const bool optimize_ionvar_copies) - : printer(std::make_unique(output_dir + "/" + mod_filename + ".cpp")) - , mod_filename(std::move(mod_filename)) - , float_type(std::move(float_type)) - , optimize_ionvar_copies(optimize_ionvar_copies) {} - - - /// This constructor is private, only the derived classes' public constructors are public - CodegenCppVisitor(std::string mod_filename, - std::ostream& stream, - std::string float_type, - const bool optimize_ionvar_copies) - : printer(std::make_unique(stream)) - , mod_filename(std::move(mod_filename)) - , float_type(std::move(float_type)) - , optimize_ionvar_copies(optimize_ionvar_copies) {} - - /****************************************************************************************/ /* Overloaded visitor routines */ /****************************************************************************************/ diff --git a/src/codegen/codegen_neuron_cpp_visitor.hpp b/src/codegen/codegen_neuron_cpp_visitor.hpp index 730e9ceec9..0d30fa2111 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.hpp +++ b/src/codegen/codegen_neuron_cpp_visitor.hpp @@ -69,6 +69,9 @@ enum InterpreterWrapper { HOC, Python }; * have removed return from verbatim block. */ class CodegenNeuronCppVisitor: public CodegenCppVisitor { + public: + using CodegenCppVisitor::CodegenCppVisitor; + protected: /****************************************************************************************/ /* Member variables */ @@ -640,51 +643,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor { public: - /** - * \brief Constructs the C++ code generator visitor - * - * This constructor instantiates an NMODL C++ code generator and allows writing generated code - * directly to a file in \c [output_dir]/[mod_filename].cpp. - * - * \note No code generation is performed at this stage. Since the code - * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c - * visit_program in order to generate the C++ code corresponding to the AST. - * - * \param mod_filename The name of the model for which code should be generated. - * It is used for constructing an output filename. - * \param output_dir The directory where target C++ file should be generated. - * \param float_type The float type to use in the generated code. The string will be used - * as-is in the target code. This defaults to \c double. - */ - CodegenNeuronCppVisitor(std::string mod_filename, - const std::string& output_dir, - std::string float_type, - const bool optimize_ionvar_copies) - : CodegenCppVisitor(mod_filename, output_dir, float_type, optimize_ionvar_copies) {} - - /** - * \copybrief nmodl::codegen::CodegenNeuronCppVisitor - * - * This constructor instantiates an NMODL C++ code generator and allows writing generated code - * into an output stream. - * - * \note No code generation is performed at this stage. Since the code - * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c - * visit_program in order to generate the C++ code corresponding to the AST. - * - * \param mod_filename The name of the model for which code should be generated. - * It is used for constructing an output filename. - * \param stream The output stream onto which to write the generated code - * \param float_type The float type to use in the generated code. The string will be used - * as-is in the target code. This defaults to \c double. - */ - CodegenNeuronCppVisitor(std::string mod_filename, - std::ostream& stream, - std::string float_type, - const bool optimize_ionvar_copies) - : CodegenCppVisitor(mod_filename, stream, float_type, optimize_ionvar_copies) {} - - /****************************************************************************************/ /* Public printing routines for code generation for use in unit tests */ /****************************************************************************************/