diff --git a/src/ast/ast_common.hpp b/src/ast/ast_common.hpp index 96fd6a7f7d..a167cd9624 100644 --- a/src/ast/ast_common.hpp +++ b/src/ast/ast_common.hpp @@ -23,10 +23,8 @@ #include "symtab/symbol_table.hpp" #include "visitors/visitor.hpp" -namespace nmodl { - /// Abstract Syntax Tree (AST) related implementations -namespace ast { +namespace nmodl::ast { /** * @defgroup ast AST Implementation @@ -96,5 +94,4 @@ static const std::string ReactionOpNames[] = {"<->", "<<", "->"}; /** @} */ // end of ast_prop -} // namespace ast -} // namespace nmodl +} // namespace nmodl::ast diff --git a/src/codegen/codegen_acc_visitor.cpp b/src/codegen/codegen_acc_visitor.cpp index 03a7589ff7..05e1fd6f92 100644 --- a/src/codegen/codegen_acc_visitor.cpp +++ b/src/codegen/codegen_acc_visitor.cpp @@ -12,8 +12,7 @@ #include "ast/protect_statement.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { /****************************************************************************************/ /* Routines must be overloaded in backend */ @@ -376,5 +375,4 @@ void CodegenAccVisitor::print_dt_update_to_device() const { get_variable_name(naming::NTHREAD_DT_VARIABLE)); } -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_acc_visitor.hpp b/src/codegen/codegen_acc_visitor.hpp index 1a3f60503f..dd5c337a9a 100644 --- a/src/codegen/codegen_acc_visitor.hpp +++ b/src/codegen/codegen_acc_visitor.hpp @@ -15,8 +15,7 @@ #include "codegen/codegen_cpp_visitor.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { /** * \addtogroup codegen_backends @@ -116,13 +115,13 @@ class CodegenAccVisitor: public CodegenCppVisitor { void print_net_send_buf_update_to_host() const override; /// update NetSendBuffer_t count from host to device - virtual void print_net_send_buf_count_update_to_device() const override; + void print_net_send_buf_count_update_to_device() const override; /// update dt from host to device - virtual void print_dt_update_to_device() const override; + void print_dt_update_to_device() const override; // synchronise/wait on stream specific to NrnThread - virtual void print_device_stream_wait() const override; + void print_device_stream_wait() const override; /// print atomic capture pragma void print_device_atomic_capture_annotation() const override; @@ -151,5 +150,4 @@ class CodegenAccVisitor: public CodegenCppVisitor { /** \} */ // end of codegen_backends -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_compatibility_visitor.cpp b/src/codegen/codegen_compatibility_visitor.cpp index 5ed3a41963..8648116ecd 100644 --- a/src/codegen/codegen_compatibility_visitor.cpp +++ b/src/codegen/codegen_compatibility_visitor.cpp @@ -12,9 +12,7 @@ #include "utils/logger.hpp" #include "visitors/visitor_utils.hpp" - -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { const std::map CodegenCompatibilityVisitor::unhandled_ast_types_func( @@ -101,7 +99,7 @@ std::string CodegenCompatibilityVisitor::return_error_if_no_bbcore_read_write( parser::CDriver driver; driver.scan_string(verbatim_statement_string); - auto tokens = driver.all_tokens(); + const auto& tokens = driver.all_tokens(); for (const auto& token: tokens) { if (token == "bbcore_read") { @@ -132,7 +130,7 @@ std::string CodegenCompatibilityVisitor::return_error_if_no_bbcore_read_write( bool CodegenCompatibilityVisitor::find_unhandled_ast_nodes(Ast& node) const { std::vector unhandled_ast_types; unhandled_ast_types.reserve(unhandled_ast_types_func.size()); - for (auto [node_type, _]: unhandled_ast_types_func) { + for (const auto& [node_type, _]: unhandled_ast_types_func) { unhandled_ast_types.push_back(node_type); } const auto& unhandled_ast_nodes = collect_nodes(node, unhandled_ast_types); @@ -158,5 +156,4 @@ bool CodegenCompatibilityVisitor::find_unhandled_ast_nodes(Ast& node) const { return false; } -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_compatibility_visitor.hpp b/src/codegen/codegen_compatibility_visitor.hpp index 311c540efb..0a3f2a5947 100644 --- a/src/codegen/codegen_compatibility_visitor.hpp +++ b/src/codegen/codegen_compatibility_visitor.hpp @@ -22,8 +22,7 @@ #include "utils/logger.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { using namespace ast; @@ -157,5 +156,4 @@ class CodegenCompatibilityVisitor: public visitor::AstVisitor { /** \} */ // end of codegen_backends -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index e661f5685b..762503a34e 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -28,8 +28,7 @@ #include "visitors/var_usage_visitor.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { using namespace ast; @@ -529,12 +528,6 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const { return current; } - -int CodegenCppVisitor::float_variables_size() const { - return codegen_float_variables.size(); -} - - int CodegenCppVisitor::int_variables_size() const { const auto count_semantics = [](int sum, const IndexSemantics& sem) { return sum += sem.size; }; return std::accumulate(info.semantics.begin(), info.semantics.end(), 0, count_semantics); @@ -554,23 +547,22 @@ std::vector CodegenCppVisitor::ion_read_statements(BlockType type) } std::vector statements; for (const auto& ion: info.ions) { - auto name = ion.name; for (const auto& var: ion.reads) { auto const iter = std::find(ion.implicit_reads.begin(), ion.implicit_reads.end(), var); if (iter != ion.implicit_reads.end()) { continue; } - auto variable_names = read_ion_variable_name(var); - auto first = get_variable_name(variable_names.first); - auto second = get_variable_name(variable_names.second); - statements.push_back(fmt::format("{} = {};", first, second)); + const auto& [dest, src] = read_ion_variable_name(var); + auto dest_var = get_variable_name(dest); + auto src_var = get_variable_name(src); + statements.push_back(fmt::format("{} = {};", dest_var, src_var)); } for (const auto& var: ion.writes) { if (ion.is_ionic_conc(var)) { - auto variables = read_ion_variable_name(var); - auto first = get_variable_name(variables.first); - auto second = get_variable_name(variables.second); - statements.push_back(fmt::format("{} = {};", first, second)); + const auto& [dest, src] = read_ion_variable_name(var); + auto dest_var = get_variable_name(dest); + auto src_var = get_variable_name(src); + statements.push_back(fmt::format("{} = {};", dest_var, src_var)); } } } @@ -578,33 +570,55 @@ std::vector CodegenCppVisitor::ion_read_statements(BlockType type) } -std::vector CodegenCppVisitor::ion_read_statements_optimized(BlockType type) const { +std::vector CodegenCppVisitor::ion_read_statements_optimized(BlockType /* type */) const { std::vector statements; for (const auto& ion: info.ions) { for (const auto& var: ion.writes) { if (ion.is_ionic_conc(var)) { - auto variables = read_ion_variable_name(var); - auto first = "ionvar." + variables.first; - const auto& second = get_variable_name(variables.second); - statements.push_back(fmt::format("{} = {};", first, second)); + const auto& [dest, src] = read_ion_variable_name(var); + auto dest_var = "ionvar." + dest; + const auto& src_var = get_variable_name(src); + statements.push_back(fmt::format("{} = {};", dest_var, src_var)); } } } return statements; } + +void CodegenCppVisitor::handle_initial_ion_write_statement(const Ion& ion, + const std::string& concentration, + std::vector& statements) const { + int index = 0; + if (ion.is_intra_cell_conc(concentration)) { + index = 1; + } else if (ion.is_extra_cell_conc(concentration)) { + index = 2; + } else { + /// \todo Unhandled case in neuron implementation + throw std::logic_error(fmt::format("codegen error for {} ion", ion.name)); + } + auto ion_type_name = fmt::format("{}_type", ion.name); + auto lhs = fmt::format("int {}", ion_type_name); + auto op = "="; + auto rhs = get_variable_name(ion_type_name); + statements.push_back(ShadowUseStatement{lhs, op, rhs}); + auto statement = conc_write_statement(ion.name, concentration, index); + statements.push_back(ShadowUseStatement{statement, "", ""}); + +} + // NOLINTNEXTLINE(readability-function-cognitive-complexity) -std::vector CodegenCppVisitor::ion_write_statements(BlockType type) { +std::vector CodegenCppVisitor::ion_write_statements(BlockType type) const { std::vector statements; for (const auto& ion: info.ions) { std::string concentration; - auto name = ion.name; for (const auto& var: ion.writes) { - auto variable_names = write_ion_variable_name(var); + const auto& [dest, src] = write_ion_variable_name(var); if (ion.is_ionic_current(var)) { if (type == BlockType::Equation) { auto current = breakpoint_current(var); - auto lhs = variable_names.first; + const auto& lhs = dest; auto op = "+="; auto rhs = get_variable_name(current); if (info.point_process) { @@ -617,30 +631,15 @@ std::vector CodegenCppVisitor::ion_write_statements(BlockTyp if (!ion.is_rev_potential(var)) { concentration = var; } - auto lhs = variable_names.first; + const auto& lhs = dest; auto op = "="; - auto rhs = get_variable_name(variable_names.second); + const auto& rhs = get_variable_name(src); statements.push_back(ShadowUseStatement{lhs, op, rhs}); } } if (type == BlockType::Initial && !concentration.empty()) { - int index = 0; - if (ion.is_intra_cell_conc(concentration)) { - index = 1; - } else if (ion.is_extra_cell_conc(concentration)) { - index = 2; - } else { - /// \todo Unhandled case in neuron implementation - throw std::logic_error(fmt::format("codegen error for {} ion", ion.name)); - } - auto ion_type_name = fmt::format("{}_type", ion.name); - auto lhs = fmt::format("int {}", ion_type_name); - auto op = "="; - auto rhs = get_variable_name(ion_type_name); - statements.push_back(ShadowUseStatement{lhs, op, rhs}); - auto statement = conc_write_statement(ion.name, concentration, index); - statements.push_back(ShadowUseStatement{statement, "", ""}); + handle_initial_ion_write_statement(ion, concentration, statements); } } return statements; @@ -742,7 +741,7 @@ void CodegenCppVisitor::update_index_semantics() { info.semantics.emplace_back(index++, fmt::format("#{}_ion", ion.name), 1); } } - for (auto& var: info.pointer_variables) { + for (const auto& var: info.pointer_variables) { if (info.first_pointer_var_index == -1) { info.first_pointer_var_index = index; } @@ -1373,8 +1372,6 @@ void CodegenCppVisitor::print_function_prototypes() { static const TableStatement* get_table_statement(const ast::Block& node) { - // TableStatementVisitor v; - const auto& table_statements = collect_nodes(node, {AstNodeType::TABLE_STATEMENT}); if (table_statements.size() != 1) { @@ -1387,7 +1384,7 @@ static const TableStatement* get_table_statement(const ast::Block& node) { } -std::tuple CodegenCppVisitor::check_if_var_is_array(const std::string& name) { +std::tuple CodegenCppVisitor::check_if_var_is_array(const std::string& name) const { auto symbol = program_symtab->lookup_in_scope(name); if (!symbol) { throw std::runtime_error( @@ -1403,8 +1400,8 @@ std::tuple CodegenCppVisitor::check_if_var_is_array(const std::string void CodegenCppVisitor::print_table_check_function(const Block& node) { auto statement = get_table_statement(node); - auto table_variables = statement->get_table_vars(); - auto depend_variables = statement->get_depend_vars(); + const auto& table_variables = statement->get_table_vars(); + const auto& depend_variables = statement->get_depend_vars(); const auto& from = statement->get_from(); const auto& to = statement->get_to(); auto name = node.get_node_name(); @@ -1413,7 +1410,6 @@ void CodegenCppVisitor::print_table_check_function(const Block& node) { auto use_table_var = get_variable_name(naming::USE_TABLE_VARIABLE); auto tmin_name = get_variable_name("tmin_" + name); auto mfac_name = get_variable_name("mfac_" + name); - auto float_type = default_float_data_type(); printer->add_newline(2); print_device_method_annotation(); @@ -1427,7 +1423,7 @@ void CodegenCppVisitor::print_table_check_function(const Block& node) { printer->add_line("static bool make_table = true;"); for (const auto& variable: depend_variables) { - printer->fmt_line("static {} save_{};", float_type, variable->get_node_name()); + printer->fmt_line("static {} save_{};", default_float_data_type(), variable->get_node_name()); } for (const auto& variable: depend_variables) { @@ -1922,7 +1918,7 @@ void CodegenCppVisitor::print_eigen_linear_solver(const std::string& float_type, /****************************************************************************************/ -std::string CodegenCppVisitor::internal_method_arguments() { +std::string CodegenCppVisitor::internal_method_arguments() const { if (ion_variable_struct_required()) { return "id, pnodecount, inst, ionvar, data, indexes, thread, nt, v"; } @@ -1933,7 +1929,7 @@ std::string CodegenCppVisitor::internal_method_arguments() { /** * @todo: figure out how to correctly handle qualifiers */ -CodegenCppVisitor::ParamVector CodegenCppVisitor::internal_method_parameters() { +CodegenCppVisitor::ParamVector CodegenCppVisitor::internal_method_parameters() const { ParamVector params; params.emplace_back("", "int", "", "id"); params.emplace_back("", "int", "", "pnodecount"); @@ -1977,7 +1973,7 @@ std::string CodegenCppVisitor::nrn_thread_arguments() const { * Function call arguments when function or procedure is defined in the * same mod file itself */ -std::string CodegenCppVisitor::nrn_thread_internal_arguments() { +std::string CodegenCppVisitor::nrn_thread_internal_arguments() const { if (ion_variable_struct_required()) { return "id, pnodecount, inst, ionvar, data, indexes, thread, nt, v"; } @@ -2076,7 +2072,7 @@ std::pair CodegenCppVisitor::write_ion_variable_name( std::string CodegenCppVisitor::conc_write_statement(const std::string& ion_name, const std::string& concentration, - int index) { + int index) const { auto conc_var_name = get_variable_name(naming::ION_VARNAME_PREFIX + concentration); auto style_var_name = get_variable_name("style_" + ion_name); return fmt::format( @@ -2103,7 +2099,7 @@ std::string CodegenCppVisitor::conc_write_statement(const std::string& ion_name, * to queue that will be used in reduction queue. */ std::string CodegenCppVisitor::process_shadow_update_statement(const ShadowUseStatement& statement, - BlockType /* type */) { + BlockType /* type */) const { // when there is no operator or rhs then that statement doesn't need shadow update if (statement.op.empty() && statement.rhs.empty()) { auto text = statement.lhs + ";"; @@ -2525,7 +2521,7 @@ void CodegenCppVisitor::print_mechanism_global_var_structure(bool print_initiali // is false. But as v is always local variable and passed as argument, // we don't need to use global variable v - auto& top_locals = info.top_local_variables; + const auto& top_locals = info.top_local_variables; if (!info.vectorize && !top_locals.empty()) { for (const auto& var: top_locals) { auto name = var->get_name(); @@ -2587,7 +2583,7 @@ void CodegenCppVisitor::print_mechanism_global_var_structure(bool print_initiali for (const auto& var: info.constant_variables) { auto const name = var->get_name(); - auto* const value_ptr = var->get_value().get(); + const auto* const value_ptr = var->get_value().get(); double const value{value_ptr ? *value_ptr : 0}; printer->fmt_line("{}{} {}{};", qualifier, @@ -3075,13 +3071,13 @@ void CodegenCppVisitor::print_mechanism_range_var_structure(bool print_initializ print_initializers ? fmt::format("{{&coreneuron::{}}}", name) : std::string{}); } - for (auto& var: codegen_float_variables) { + for (const auto& var: codegen_float_variables) { const auto& name = var->get_name(); auto type = get_range_var_float_type(var); auto qualifier = is_constant_variable(name) ? "const " : ""; printer->fmt_line("{}{}* {}{};", qualifier, type, name, value_initialize); } - for (auto& var: codegen_int_variables) { + for (const auto& var: codegen_int_variables) { const auto& name = var.symbol->get_name(); if (var.is_index || var.is_integer) { auto qualifier = var.is_constant ? "const " : ""; @@ -3179,7 +3175,7 @@ void CodegenCppVisitor::print_setup_range_variable() { * are pointers to internal variables (e.g. ions). Hence, we check if given * variable can be safely converted to new type. If so, return new type. */ -std::string CodegenCppVisitor::get_range_var_float_type(const SymbolType& symbol) { +std::string CodegenCppVisitor::get_range_var_float_type(const SymbolType& symbol) const { // clang-format off auto with = NmodlType::read_ion_var | NmodlType::write_ion_var @@ -3283,7 +3279,7 @@ void CodegenCppVisitor::print_instance_variable_setup() { id += var->get_length(); } - for (auto& var: codegen_int_variables) { + for (const auto& var: codegen_int_variables) { auto name = var.symbol->get_name(); auto const variable = [&var]() { if (var.is_index || var.is_integer) { @@ -3341,9 +3337,9 @@ void CodegenCppVisitor::print_initial_block(const InitialBlock* node) { } // write ion statements - auto write_statements = ion_write_statements(BlockType::Initial); - for (auto& statement: write_statements) { - auto text = process_shadow_update_statement(statement, BlockType::Initial); + const auto& write_statements = ion_write_statements(BlockType::Initial); + for (const auto& statement: write_statements) { + const auto& text = process_shadow_update_statement(statement, BlockType::Initial); printer->add_line(text); } } @@ -3748,8 +3744,8 @@ void CodegenCppVisitor::print_net_receive_common_code(const Block& node, bool ne if (!parameters.empty()) { int i = 0; printer->add_newline(); - for (auto& parameter: parameters) { - auto name = parameter->get_node_name(); + for (const auto& parameter: parameters) { + const auto& name = parameter->get_node_name(); bool var_used = VarUsageVisitor().variable_used(node, "(*" + name + ")"); if (var_used) { printer->fmt_line("double* {} = weights + weight_index + {};", name, i); @@ -4363,7 +4359,7 @@ void CodegenCppVisitor::print_nrn_current(const BreakpointBlock& node) { get_parameter_str(args)); printer->add_line("double current = 0.0;"); print_statement_block(*block, false, false); - for (auto& current: info.currents) { + for (const auto& current: info.currents) { const auto& name = get_variable_name(current); printer->fmt_line("current += {};", name); } @@ -4409,12 +4405,12 @@ void CodegenCppVisitor::print_nrn_cur_conductance_kernel(const BreakpointBlock& } -void CodegenCppVisitor::print_nrn_cur_non_conductance_kernel() { +void CodegenCppVisitor::print_nrn_cur_non_conductance_kernel() const { printer->fmt_line("double g = nrn_current_{}({}+0.001);", info.mod_suffix, internal_method_arguments()); - for (auto& ion: info.ions) { - for (auto& var: ion.writes) { + for (const auto& ion: info.ions) { + for (const auto& var: ion.writes) { if (ion.is_ionic_current(var)) { const auto& name = get_variable_name(var); printer->fmt_line("double di{} = {};", ion.name, name); @@ -4687,5 +4683,4 @@ void CodegenCppVisitor::visit_program(const Program& node) { print_codegen_routines(); } -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index ee0344058c..2b729d81cb 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -33,9 +33,7 @@ /// encapsulates code generation backend implementations -namespace nmodl { - -namespace codegen { +namespace nmodl::codegen { /** * \defgroup codegen Code Generation Implementation @@ -498,7 +496,9 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { /** * Number of float variables in the model */ - int float_variables_size() const; + auto float_variables_size() const { + return codegen_float_variables.size(); + } /** @@ -733,9 +733,12 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * \param type The type of code block being generated * \return A \c vector of strings representing the write-back of ion variables */ - std::vector ion_write_statements(BlockType type); + std::vector ion_write_statements(BlockType type) const; + void handle_initial_ion_write_statement(const Ion& ion, + const std::string& concentration, + std::vector& statements) const; /** * Return ion variable name and corresponding ion read variable name * \param name The ion variable name @@ -761,21 +764,21 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { */ std::string conc_write_statement(const std::string& ion_name, const std::string& concentration, - int index); + int index) const; /** * Arguments for functions that are defined and used internally. * \return the method arguments */ - std::string internal_method_arguments(); + std::string internal_method_arguments() const; /** * Parameters for internally defined functions * \return the method parameters */ - ParamVector internal_method_parameters(); + ParamVector internal_method_parameters() const; /** @@ -812,7 +815,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { /** * Arguments for "_threadargs_" macro in neuron implementation */ - std::string nrn_thread_internal_arguments(); + std::string nrn_thread_internal_arguments() const; /** @@ -956,7 +959,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * \return \c return a tuple if variable * is an array otherwise */ - std::tuple check_if_var_is_array(const std::string& name); + std::tuple check_if_var_is_array(const std::string& name) const; /** * Print declaration of macro NRN_PRCELLSTATE for debugging @@ -1002,7 +1005,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Returns floating point type for given range variable symbol * \param symbol A range variable symbol */ - std::string get_range_var_float_type(const SymbolType& symbol); + std::string get_range_var_float_type(const SymbolType& symbol) const; /** @@ -1407,7 +1410,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * \return The generated target backend code */ std::string process_shadow_update_statement(const ShadowUseStatement& statement, - BlockType type); + BlockType type) const; /** @@ -1434,7 +1437,7 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * If the NMODL \c conductance keyword is \b not used in the \c breakpoint block, then * CodegenCppVisitor::print_nrn_cur_kernel will use this printer */ - void print_nrn_cur_non_conductance_kernel(); + void print_nrn_cur_non_conductance_kernel() const; /** @@ -1865,5 +1868,4 @@ void CodegenCppVisitor::print_function_declaration(const T& node, const std::str /** \} */ // end of codegen_backends -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_helper_visitor.cpp b/src/codegen/codegen_helper_visitor.cpp index fa9e4438b6..40ed8c0785 100644 --- a/src/codegen/codegen_helper_visitor.cpp +++ b/src/codegen/codegen_helper_visitor.cpp @@ -16,8 +16,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { using namespace ast; @@ -774,5 +773,4 @@ void CodegenHelperVisitor::visit_after_block(const ast::AfterBlock& node) { info.before_after_blocks.push_back(&node); } -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_helper_visitor.hpp b/src/codegen/codegen_helper_visitor.hpp index b960bdc06f..daf483e461 100644 --- a/src/codegen/codegen_helper_visitor.hpp +++ b/src/codegen/codegen_helper_visitor.hpp @@ -18,8 +18,7 @@ #include "symtab/symbol_table.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { /** * @addtogroup codegen_details @@ -119,5 +118,4 @@ class CodegenHelperVisitor: public visitor::ConstAstVisitor { /** @} */ // end of codegen_details -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_info.cpp b/src/codegen/codegen_info.cpp index b7d40125a6..b5a2dcff69 100644 --- a/src/codegen/codegen_info.cpp +++ b/src/codegen/codegen_info.cpp @@ -12,8 +12,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { using visitor::VarUsageVisitor; @@ -106,5 +105,4 @@ bool CodegenInfo::is_voltage_used_by_watch_statements() const { }); } -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_info.hpp b/src/codegen/codegen_info.hpp index 67cf6c9bb4..b3bcb19bf9 100644 --- a/src/codegen/codegen_info.hpp +++ b/src/codegen/codegen_info.hpp @@ -20,8 +20,7 @@ #include "ast/ast.hpp" #include "symtab/symbol_table.hpp" -namespace nmodl { -namespace codegen { +namespace nmodl::codegen { /** * \addtogroup codegen_details @@ -439,5 +438,4 @@ struct CodegenInfo { /** \} */ // end of codegen_backends -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen diff --git a/src/codegen/codegen_naming.hpp b/src/codegen/codegen_naming.hpp index 3af8a49e88..c56af84218 100644 --- a/src/codegen/codegen_naming.hpp +++ b/src/codegen/codegen_naming.hpp @@ -11,10 +11,7 @@ #include -namespace nmodl { -namespace codegen { -/// different variable names used in code generation -namespace naming { +namespace nmodl::codegen::naming { /// nmodl language version /// @todo : should be moved from codegen to global scope @@ -179,6 +176,4 @@ static constexpr char ION_VARNAME_PREFIX[] = "ion_"; {"_tqitem", "tqitem"}}; // clang-format on -} // namespace naming -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen::naming diff --git a/src/codegen/codegen_utils.cpp b/src/codegen/codegen_utils.cpp index 5f7b623239..1567c12c9a 100644 --- a/src/codegen/codegen_utils.cpp +++ b/src/codegen/codegen_utils.cpp @@ -9,9 +9,7 @@ #include "codegen/codegen_cpp_visitor.hpp" -namespace nmodl { -namespace codegen { -namespace utils { +namespace nmodl::codegen::utils { /** * \details We can directly print value but if user specify value as integer then * then it gets printed as an integer. To avoid this, we use below wrappers. @@ -38,6 +36,4 @@ std::string format_float_string(const std::string& s_value) { } return s_value; } -} // namespace utils -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen::utils diff --git a/src/codegen/codegen_utils.hpp b/src/codegen/codegen_utils.hpp index 4c910b36b5..f817eb8c58 100644 --- a/src/codegen/codegen_utils.hpp +++ b/src/codegen/codegen_utils.hpp @@ -15,9 +15,7 @@ #include -namespace nmodl { -namespace codegen { -namespace utils { +namespace nmodl::codegen::utils { /** * Handles the double constants format being printed in the generated code. @@ -46,6 +44,4 @@ std::string format_double_string(const std::string& s_value); template std::string format_float_string(const std::string& s_value); -} // namespace utils -} // namespace codegen -} // namespace nmodl +} // namespace nmodl::codegen::utils diff --git a/src/language/nodes.py b/src/language/nodes.py index fc45edf181..4e440b884f 100644 --- a/src/language/nodes.py +++ b/src/language/nodes.py @@ -196,13 +196,17 @@ def get_typename(self): return type_name + @classmethod + def add_const_rvalue_reference(cls, type): + return f"const {type}&" + def get_rvalue_typename(self): """returns rvalue reference type of the node""" typename = self.get_typename() if self.is_vector: - return "const " + typename + "&" + return self.add_const_rvalue_reference(typename) if self.is_base_type_node and not self.is_integral_type_node or self.is_ptr_excluded_node: - return "const " + typename + "&" + return self.add_const_rvalue_reference(typename) return typename def get_shared_typename(self): @@ -245,7 +249,7 @@ def member_rvalue_typename(self): """returns rvalue reference type when used as returned or parameter type""" typename = self.member_typename if not self.is_integral_type_node: - return "const " + typename + "&" + return self.add_const_rvalue_reference(typename) return typename def get_add_methods_declaration(self): diff --git a/src/lexer/c11_lexer.hpp b/src/lexer/c11_lexer.hpp index b95c1baf95..117f9d7b2e 100644 --- a/src/lexer/c11_lexer.hpp +++ b/src/lexer/c11_lexer.hpp @@ -28,8 +28,7 @@ #include "FlexLexer.h" #endif -namespace nmodl { -namespace parser { +namespace nmodl::parser { /** * @addtogroup lexer @@ -108,5 +107,4 @@ class CLexer: public CFlexLexer { /** @} */ // end of lexer -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/lexer/diffeq_lexer.hpp b/src/lexer/diffeq_lexer.hpp index bf6202aac7..ef39abe50e 100644 --- a/src/lexer/diffeq_lexer.hpp +++ b/src/lexer/diffeq_lexer.hpp @@ -28,8 +28,7 @@ #include "FlexLexer.h" #endif -namespace nmodl { -namespace parser { +namespace nmodl::parser { /** * @addtogroup lexer @@ -80,5 +79,4 @@ class DiffeqLexer: public DiffEqFlexLexer { /** @} */ // end of lexer -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/lexer/nmodl_lexer.hpp b/src/lexer/nmodl_lexer.hpp index e89db2a04c..1a135800cc 100644 --- a/src/lexer/nmodl_lexer.hpp +++ b/src/lexer/nmodl_lexer.hpp @@ -35,8 +35,7 @@ #include "FlexLexer.h" #endif -namespace nmodl { -namespace parser { +namespace nmodl::parser { /** * @defgroup lexer Lexer Implementation @@ -154,5 +153,4 @@ class NmodlLexer: public NmodlFlexLexer { /** @} */ // end of lexer -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/lexer/unit_lexer.hpp b/src/lexer/unit_lexer.hpp index c7651c3137..839b017a44 100644 --- a/src/lexer/unit_lexer.hpp +++ b/src/lexer/unit_lexer.hpp @@ -28,8 +28,7 @@ #include "FlexLexer.h" #endif -namespace nmodl { -namespace parser { +namespace nmodl::parser { /** * @addtogroup lexer @@ -83,5 +82,4 @@ class UnitLexer: public UnitFlexLexer { virtual UnitParser::symbol_type next_token(); }; -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/c11_driver.cpp b/src/parser/c11_driver.cpp index a48799d7d8..d9d1559f84 100644 --- a/src/parser/c11_driver.cpp +++ b/src/parser/c11_driver.cpp @@ -11,8 +11,7 @@ #include "lexer/c11_lexer.hpp" #include "parser/c11_driver.hpp" -namespace nmodl { -namespace parser { +namespace nmodl::parser { CDriver::CDriver() = default; @@ -75,5 +74,4 @@ void CDriver::scan_string(const std::string& text) { } } -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/c11_driver.hpp b/src/parser/c11_driver.hpp index 555f6a5050..c9558266e2 100644 --- a/src/parser/c11_driver.hpp +++ b/src/parser/c11_driver.hpp @@ -14,8 +14,7 @@ #include -namespace nmodl { -namespace parser { +namespace nmodl::parser { /// flex generated scanner class (extends base lexer class of flex) class CLexer; @@ -109,5 +108,4 @@ class CDriver { /** \} */ // end of parser -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/diffeq_context.cpp b/src/parser/diffeq_context.cpp index 298b2185d9..7cbc5239c7 100644 --- a/src/parser/diffeq_context.cpp +++ b/src/parser/diffeq_context.cpp @@ -11,9 +11,7 @@ #include "utils/string_utils.hpp" -namespace nmodl { -namespace parser { -namespace diffeq { +namespace nmodl::parser::diffeq { Term::Term(const std::string& expr, const std::string& state) : expr(expr) @@ -182,6 +180,4 @@ std::string DiffEqContext::get_solution(bool& cnexp_possible) { return solution; } -} // namespace diffeq -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser::diffeq diff --git a/src/parser/diffeq_context.hpp b/src/parser/diffeq_context.hpp index 08fde3a300..eb83d5eeb0 100644 --- a/src/parser/diffeq_context.hpp +++ b/src/parser/diffeq_context.hpp @@ -10,9 +10,7 @@ #include #include -namespace nmodl { -namespace parser { -namespace diffeq { +namespace nmodl::parser::diffeq { /** * \class Term @@ -127,6 +125,4 @@ class DiffEqContext { void print() const; }; -} // namespace diffeq -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser::diffeq diff --git a/src/parser/diffeq_driver.cpp b/src/parser/diffeq_driver.cpp index 5cf92a1ca6..7b4dc6072e 100644 --- a/src/parser/diffeq_driver.cpp +++ b/src/parser/diffeq_driver.cpp @@ -12,8 +12,7 @@ #include "parser/diffeq_driver.hpp" #include "utils/string_utils.hpp" -namespace nmodl { -namespace parser { +namespace nmodl::parser { void DiffeqDriver::parse_equation(const std::string& equation, std::string& state, @@ -71,5 +70,4 @@ bool DiffeqDriver::cnexp_possible(const std::string& equation, std::string& solu return cnexp_possible; } -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/diffeq_driver.hpp b/src/parser/diffeq_driver.hpp index 2162cf41c9..a247913dd8 100644 --- a/src/parser/diffeq_driver.hpp +++ b/src/parser/diffeq_driver.hpp @@ -12,8 +12,7 @@ #include "parser/diffeq_context.hpp" -namespace nmodl { -namespace parser { +namespace nmodl::parser { /// flex generated scanner class (extends base lexer class of flex) class DiffeqlLexer; @@ -60,5 +59,4 @@ class DiffeqDriver { /** @} */ // end of parser -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/diffeq_helper.hpp b/src/parser/diffeq_helper.hpp index c04111d788..55041625a8 100644 --- a/src/parser/diffeq_helper.hpp +++ b/src/parser/diffeq_helper.hpp @@ -9,9 +9,6 @@ #include "parser/diffeq_context.hpp" -namespace nmodl { -namespace parser { - /** * \brief Helper functions for solving differential equations * @@ -23,7 +20,7 @@ namespace parser { * Need to revisit this, may be using better library like symengine * altogether. */ -namespace diffeq { + namespace nmodl::parser::diffeq { /// operators beign supported as part of binary expressions enum class MathOp { add = 1, sub, mul, div }; @@ -175,6 +172,4 @@ inline Term eval_derivative(const Term& first, return solution; } -} // namespace diffeq -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser::diffeq diff --git a/src/parser/nmodl_driver.cpp b/src/parser/nmodl_driver.cpp index 63f50cc3a5..c803e11b01 100644 --- a/src/parser/nmodl_driver.cpp +++ b/src/parser/nmodl_driver.cpp @@ -15,8 +15,7 @@ namespace fs = std::filesystem; -namespace nmodl { -namespace parser { +namespace nmodl::parser { NmodlDriver::NmodlDriver(bool strace, bool ptrace) : trace_scanner(strace) @@ -164,5 +163,4 @@ std::string NmodlDriver::check_include_argument(const location& location, return filename.substr(1, filename.size() - 2); } -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/nmodl_driver.hpp b/src/parser/nmodl_driver.hpp index 217879b053..304b0d2e1c 100644 --- a/src/parser/nmodl_driver.hpp +++ b/src/parser/nmodl_driver.hpp @@ -23,9 +23,7 @@ /// encapsulates everything related to NMODL code generation framework -namespace nmodl { -/// encapsulate lexer and parsers implementations -namespace parser { +namespace nmodl::parser { /** * \defgroup parser Parser Implementation @@ -162,5 +160,4 @@ class NmodlDriver { /** \} */ // end of parser -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/unit_driver.cpp b/src/parser/unit_driver.cpp index 5f709b6398..0b286fe0dd 100644 --- a/src/parser/unit_driver.cpp +++ b/src/parser/unit_driver.cpp @@ -11,8 +11,7 @@ #include "lexer/unit_lexer.hpp" #include "parser/unit_driver.hpp" -namespace nmodl { -namespace parser { +namespace nmodl::parser { /// parse Units file provided as istream bool UnitDriver::parse_stream(std::istream& in) { @@ -42,5 +41,4 @@ bool UnitDriver::parse_string(const std::string& input) { return parse_stream(iss); } -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/unit_driver.hpp b/src/parser/unit_driver.hpp index 31f882e731..ee939ceacf 100644 --- a/src/parser/unit_driver.hpp +++ b/src/parser/unit_driver.hpp @@ -14,8 +14,7 @@ #include #include -namespace nmodl { -namespace parser { +namespace nmodl::parser { /// flex generated scanner class (extends base lexer class of flex) class UnitLexer; @@ -75,5 +74,4 @@ class UnitDriver { } }; -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser diff --git a/src/parser/verbatim_driver.hpp b/src/parser/verbatim_driver.hpp index bd005879af..d7b18d716b 100644 --- a/src/parser/verbatim_driver.hpp +++ b/src/parser/verbatim_driver.hpp @@ -10,8 +10,7 @@ #include -namespace nmodl { -namespace parser { +namespace nmodl::parser { /** * @addtogroup parser @@ -47,8 +46,7 @@ class VerbatimDriver { /** @} */ // end of parser -} // namespace parser -} // namespace nmodl +} // namespace nmodl::parser int Verbatim_parse(nmodl::parser::VerbatimDriver*); diff --git a/src/printer/code_printer.cpp b/src/printer/code_printer.cpp index b2e5f6d865..56156cb405 100644 --- a/src/printer/code_printer.cpp +++ b/src/printer/code_printer.cpp @@ -8,8 +8,7 @@ #include "printer/code_printer.hpp" #include "utils/string_utils.hpp" -namespace nmodl { -namespace printer { +namespace nmodl::printer { CodePrinter::CodePrinter(const std::string& filename) { if (filename.empty()) { @@ -110,5 +109,4 @@ void CodePrinter::pop_block(const std::string_view& suffix, std::size_t num_newl add_newline(num_newlines); } -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/code_printer.hpp b/src/printer/code_printer.hpp index 226562fff1..6716072d8a 100644 --- a/src/printer/code_printer.hpp +++ b/src/printer/code_printer.hpp @@ -22,9 +22,7 @@ #include #include -namespace nmodl { -/// implementation of various printers -namespace printer { +namespace nmodl::printer { /** * @defgroup printer Code Printers @@ -131,5 +129,4 @@ class CodePrinter { /** @} */ // end of printer -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/decl.hpp b/src/printer/decl.hpp index 041b2114cb..c63d03b285 100644 --- a/src/printer/decl.hpp +++ b/src/printer/decl.hpp @@ -12,10 +12,8 @@ * \brief Forward references of symbols defined in namespace nmodl::printer */ -namespace nmodl { -namespace printer { +namespace nmodl::printer { class JSONPrinter; -} -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/json_printer.cpp b/src/printer/json_printer.cpp index 0a7477afc1..d31a2dfc82 100644 --- a/src/printer/json_printer.cpp +++ b/src/printer/json_printer.cpp @@ -9,8 +9,7 @@ #include "utils/logger.hpp" -namespace nmodl { -namespace printer { +namespace nmodl::printer { /// Dump output to provided file JSONPrinter::JSONPrinter(const std::string& filename) { @@ -90,5 +89,4 @@ void JSONPrinter::flush() { } } -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/json_printer.hpp b/src/printer/json_printer.hpp index 536c112352..6f6ad347dc 100644 --- a/src/printer/json_printer.hpp +++ b/src/printer/json_printer.hpp @@ -18,8 +18,7 @@ #include #include -namespace nmodl { -namespace printer { +namespace nmodl::printer { using json = nlohmann::json; @@ -100,5 +99,4 @@ class JSONPrinter { /** @} */ // end of printer -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/nmodl_printer.cpp b/src/printer/nmodl_printer.cpp index 2e2e4494df..6e6c90b0b5 100644 --- a/src/printer/nmodl_printer.cpp +++ b/src/printer/nmodl_printer.cpp @@ -8,8 +8,7 @@ #include "printer/nmodl_printer.hpp" #include "utils/string_utils.hpp" -namespace nmodl { -namespace printer { +namespace nmodl::printer { NMODLPrinter::NMODLPrinter(const std::string& filename) { if (filename.empty()) { @@ -51,5 +50,4 @@ void NMODLPrinter::pop_level() { *result << "}"; } -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/printer/nmodl_printer.hpp b/src/printer/nmodl_printer.hpp index 5d00725465..544cdd1346 100644 --- a/src/printer/nmodl_printer.hpp +++ b/src/printer/nmodl_printer.hpp @@ -17,8 +17,7 @@ #include #include -namespace nmodl { -namespace printer { +namespace nmodl::printer { /** * @addtogroup printer @@ -70,5 +69,4 @@ class NMODLPrinter { /** @} */ // end of printer -} // namespace printer -} // namespace nmodl +} // namespace nmodl::printer diff --git a/src/pybind/docstrings.hpp b/src/pybind/docstrings.hpp index 7fa8274826..871a0c3108 100644 --- a/src/pybind/docstrings.hpp +++ b/src/pybind/docstrings.hpp @@ -7,8 +7,7 @@ #pragma once -namespace nmodl { -namespace docstring { +namespace nmodl::docstring { constexpr const char* binary_op_enum() { return R"( @@ -170,5 +169,4 @@ constexpr const char* parent_property() { )"; } -} // namespace docstring -} // namespace nmodl +} // namespace nmodl::docstring diff --git a/src/pybind/pybind_utils.hpp b/src/pybind/pybind_utils.hpp index 43ad61dccd..ed14ff91bd 100644 --- a/src/pybind/pybind_utils.hpp +++ b/src/pybind/pybind_utils.hpp @@ -13,8 +13,7 @@ #include -namespace pybind11 { -namespace detail { +namespace pybind11::detail { template struct CopyFromPython { @@ -88,8 +87,7 @@ class pythonibuf: public std::streambuf { setg(end, end, end); } }; -} // namespace detail -} // namespace pybind11 +} // namespace pybind11::details class VisitorOStreamResources { protected: diff --git a/src/pybind/pyembed.cpp b/src/pybind/pyembed.cpp index 447674a2b4..544c151529 100644 --- a/src/pybind/pyembed.cpp +++ b/src/pybind/pyembed.cpp @@ -15,9 +15,7 @@ namespace fs = std::filesystem; -namespace nmodl { - -namespace pybind_wrappers { +namespace nmodl::pybind_wrappers { bool EmbeddedPythonLoader::have_wrappers() { #if defined(NMODL_STATIC_PYWRAPPER) @@ -89,6 +87,4 @@ const pybind_wrap_api* EmbeddedPythonLoader::api() { } -} // namespace pybind_wrappers - -} // namespace nmodl +} // namespace nmodl::pybind_wrappers diff --git a/src/pybind/pyembed.hpp b/src/pybind/pyembed.hpp index 2199d6b04c..f8f2576d44 100644 --- a/src/pybind/pyembed.hpp +++ b/src/pybind/pyembed.hpp @@ -14,8 +14,7 @@ #include #include -namespace nmodl { -namespace pybind_wrappers { +namespace nmodl::pybind_wrappers { struct PythonExecutor { @@ -182,5 +181,4 @@ class EmbeddedPythonLoader { pybind_wrap_api init_pybind_wrap_api() noexcept; -} // namespace pybind_wrappers -} // namespace nmodl +} // namespace nmodl::pybind_wrappers diff --git a/src/pybind/wrapper.cpp b/src/pybind/wrapper.cpp index d456e5c2d0..a331188482 100644 --- a/src/pybind/wrapper.cpp +++ b/src/pybind/wrapper.cpp @@ -17,8 +17,7 @@ namespace py = pybind11; using namespace py::literals; -namespace nmodl { -namespace pybind_wrappers { +namespace nmodl::pybind_wrappers { void SolveLinearSystemExecutor::operator()() { const auto locals = py::dict("eq_strings"_a = eq_system, @@ -214,8 +213,7 @@ pybind_wrap_api init_pybind_wrap_api() noexcept { }; } -} // namespace pybind_wrappers -} // namespace nmodl +} // namespace nmodl::pybind_wrappers // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) diff --git a/src/pybind/wrapper.cpp.orig b/src/pybind/wrapper.cpp.orig new file mode 100644 index 0000000000..d456e5c2d0 --- /dev/null +++ b/src/pybind/wrapper.cpp.orig @@ -0,0 +1,223 @@ +/* + * Copyright 2023 Blue Brain Project, EPFL. + * See the top-level LICENSE file for details. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "codegen/codegen_naming.hpp" +#include "pybind/pyembed.hpp" + +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace py::literals; + +namespace nmodl { +namespace pybind_wrappers { + +void SolveLinearSystemExecutor::operator()() { + const auto locals = py::dict("eq_strings"_a = eq_system, + "state_vars"_a = state_vars, + "vars"_a = vars, + "small_system"_a = small_system, + "do_cse"_a = elimination, + "function_calls"_a = function_calls, + "tmp_unique_prefix"_a = tmp_unique_prefix); + py::exec(R"( + from nmodl.ode import solve_lin_system + exception_message = "" + try: + solutions, new_local_vars = solve_lin_system(eq_strings, + state_vars, + vars, + function_calls, + tmp_unique_prefix, + small_system, + do_cse) + except Exception as e: + # if we fail, fail silently and return empty string + solutions = [""] + new_local_vars = [""] + exception_message = str(e) + )", + py::globals(), + locals); + // returns a vector of solutions, i.e. new statements to add to block: + solutions = locals["solutions"].cast>(); + // and a vector of new local variables that need to be declared in the block: + new_local_vars = locals["new_local_vars"].cast>(); + // may also return a python exception message: + exception_message = locals["exception_message"].cast(); +} + + +void SolveNonLinearSystemExecutor::operator()() { + const auto locals = py::dict("equation_strings"_a = eq_system, + "state_vars"_a = state_vars, + "vars"_a = vars, + "function_calls"_a = function_calls); + py::exec(R"( + from nmodl.ode import solve_non_lin_system + exception_message = "" + try: + solutions = solve_non_lin_system(equation_strings, + state_vars, + vars, + function_calls) + except Exception as e: + # if we fail, fail silently and return empty string + solutions = [""] + new_local_vars = [""] + exception_message = str(e) + )", + py::globals(), + locals); + // returns a vector of solutions, i.e. new statements to add to block: + solutions = locals["solutions"].cast>(); + // may also return a python exception message: + exception_message = locals["exception_message"].cast(); +} + +void DiffeqSolverExecutor::operator()() { + const auto locals = py::dict("equation_string"_a = node_as_nmodl, + "dt_var"_a = dt_var, + "vars"_a = vars, + "use_pade_approx"_a = use_pade_approx, + "function_calls"_a = function_calls); + + if (method == codegen::naming::EULER_METHOD) { + // replace x' = f(x) differential equation + // with forwards Euler timestep: + // x = x + f(x) * dt + py::exec(R"( + from nmodl.ode import forwards_euler2c + exception_message = "" + try: + solution = forwards_euler2c(equation_string, dt_var, vars, function_calls) + except Exception as e: + # if we fail, fail silently and return empty string + solution = "" + exception_message = str(e) + )", + py::globals(), + locals); + } else if (method == codegen::naming::CNEXP_METHOD) { + // replace x' = f(x) differential equation + // with analytic solution for x(t+dt) in terms of x(t) + // x = ... + py::exec(R"( + from nmodl.ode import integrate2c + exception_message = "" + try: + solution = integrate2c(equation_string, dt_var, vars, + use_pade_approx) + except Exception as e: + # if we fail, fail silently and return empty string + solution = "" + exception_message = str(e) + )", + py::globals(), + locals); + } else { + // nothing to do, but the caller should know. + return; + } + solution = locals["solution"].cast(); + exception_message = locals["exception_message"].cast(); +} + +void AnalyticDiffExecutor::operator()() { + auto locals = py::dict("expressions"_a = expressions, "vars"_a = used_names_in_block); + py::exec(R"( + from nmodl.ode import differentiate2c + exception_message = "" + try: + rhs = expressions[-1].split("=", 1)[1] + solution = differentiate2c(rhs, + "v", + vars, + expressions[:-1] + ) + except Exception as e: + # if we fail, fail silently and return empty string + solution = "" + exception_message = str(e) + )", + py::globals(), + locals); + solution = locals["solution"].cast(); + exception_message = locals["exception_message"].cast(); +} + +SolveLinearSystemExecutor* create_sls_executor_func() { + return new SolveLinearSystemExecutor(); +} + +SolveNonLinearSystemExecutor* create_nsls_executor_func() { + return new SolveNonLinearSystemExecutor(); +} + +DiffeqSolverExecutor* create_des_executor_func() { + return new DiffeqSolverExecutor(); +} + +AnalyticDiffExecutor* create_ads_executor_func() { + return new AnalyticDiffExecutor(); +} + +void destroy_sls_executor_func(SolveLinearSystemExecutor* exec) { + delete exec; +} + +void destroy_nsls_executor_func(SolveNonLinearSystemExecutor* exec) { + delete exec; +} + +void destroy_des_executor_func(DiffeqSolverExecutor* exec) { + delete exec; +} + +void destroy_ads_executor_func(AnalyticDiffExecutor* exec) { + delete exec; +} + +void initialize_interpreter_func() { + pybind11::initialize_interpreter(true); + const auto python_path_cstr = std::getenv("PYTHONPATH"); + if (python_path_cstr) { + pybind11::module::import("sys").attr("path").cast().insert( + 0, python_path_cstr); + } +} + +void finalize_interpreter_func() { + pybind11::finalize_interpreter(); +} + +pybind_wrap_api init_pybind_wrap_api() noexcept { + return { + &nmodl::pybind_wrappers::initialize_interpreter_func, + &nmodl::pybind_wrappers::finalize_interpreter_func, + &nmodl::pybind_wrappers::create_sls_executor_func, + &nmodl::pybind_wrappers::create_nsls_executor_func, + &nmodl::pybind_wrappers::create_des_executor_func, + &nmodl::pybind_wrappers::create_ads_executor_func, + &nmodl::pybind_wrappers::destroy_sls_executor_func, + &nmodl::pybind_wrappers::destroy_nsls_executor_func, + &nmodl::pybind_wrappers::destroy_des_executor_func, + &nmodl::pybind_wrappers::destroy_ads_executor_func, + }; +} + +} // namespace pybind_wrappers +} // namespace nmodl + + +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +__attribute__((visibility("default"))) nmodl::pybind_wrappers::pybind_wrap_api nmodl_wrapper_api = + nmodl::pybind_wrappers::init_pybind_wrap_api(); diff --git a/src/solver/crout/crout.hpp b/src/solver/crout/crout.hpp index cf45043b72..3c5b018494 100644 --- a/src/solver/crout/crout.hpp +++ b/src/solver/crout/crout.hpp @@ -23,8 +23,7 @@ #include "coreneuron/utils/offload.hpp" #endif -namespace nmodl { -namespace crout { +namespace nmodl::crout { /** * \brief Crout matrix decomposition : in-place LU Decomposition of matrix a. @@ -203,5 +202,4 @@ nrn_pragma_omp(end declare target) #undef y_ #undef b_ -} // namespace crout -} // namespace nmodl +} // namespace nmodl::crout diff --git a/src/solver/newton/newton.hpp b/src/solver/newton/newton.hpp index 973b4cd332..0da5e7eec0 100644 --- a/src/solver/newton/newton.hpp +++ b/src/solver/newton/newton.hpp @@ -20,9 +20,7 @@ #include #include -namespace nmodl { -/// newton solver implementations -namespace newton { +namespace nmodl::newton { /** * @defgroup solver Solver Implementation @@ -237,5 +235,4 @@ EIGEN_DEVICE_FUNC int newton_solver(Eigen::Matrix& X, /** @} */ // end of solver -} // namespace newton -} // namespace nmodl +} // namespace nmodl::newton diff --git a/src/symtab/decl.hpp b/src/symtab/decl.hpp index 119ebf0f89..d287951600 100644 --- a/src/symtab/decl.hpp +++ b/src/symtab/decl.hpp @@ -10,11 +10,9 @@ /// \file /// \brief Forward declarations of symbols in namespace nmodl::symtab -namespace nmodl { -namespace symtab { +namespace nmodl::symtab { class Symbol; class SymbolTable; -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab diff --git a/src/symtab/symbol.cpp b/src/symtab/symbol.cpp index c7fe26744f..5bf47b0e03 100644 --- a/src/symtab/symbol.cpp +++ b/src/symtab/symbol.cpp @@ -9,8 +9,7 @@ #include "utils/logger.hpp" #include -namespace nmodl { -namespace symtab { +namespace nmodl::symtab { using syminfo::NmodlType; using syminfo::Status; @@ -63,5 +62,4 @@ std::vector Symbol::get_nodes_by_type( return _nodes; } -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab diff --git a/src/symtab/symbol_properties.cpp b/src/symtab/symbol_properties.cpp index 8782332ee2..fa0b0d3ded 100644 --- a/src/symtab/symbol_properties.cpp +++ b/src/symtab/symbol_properties.cpp @@ -12,9 +12,7 @@ #include "utils/string_utils.hpp" -namespace nmodl { -namespace symtab { -namespace syminfo { +namespace nmodl::symtab::syminfo { // NOLINTNEXTLINE(readability-function-cognitive-complexity) @@ -206,6 +204,4 @@ std::ostream& operator<<(std::ostream& os, const Status& obj) { return os << to_string(obj); } -} // namespace syminfo -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab::syminfo diff --git a/src/symtab/symbol_properties.hpp b/src/symtab/symbol_properties.hpp index dad35d8b60..e5b29a7c9d 100644 --- a/src/symtab/symbol_properties.hpp +++ b/src/symtab/symbol_properties.hpp @@ -17,11 +17,7 @@ #include "utils/string_utils.hpp" -namespace nmodl { -namespace symtab { - -/// %Symbol information -namespace syminfo { +namespace nmodl::symtab::syminfo { /// \todo Error with pybind if std::underlying_typ is used using enum_type = long long; @@ -285,6 +281,4 @@ std::string to_string(const T& obj) { return text; } -} // namespace syminfo -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab::syminfo diff --git a/src/symtab/symbol_table.cpp b/src/symtab/symbol_table.cpp index 638141f082..20c5b8ce53 100644 --- a/src/symtab/symbol_table.cpp +++ b/src/symtab/symbol_table.cpp @@ -13,8 +13,7 @@ #include "utils/logger.hpp" #include "utils/table_data.hpp" -namespace nmodl { -namespace symtab { +namespace nmodl::symtab { using namespace ast; using syminfo::NmodlType; @@ -527,5 +526,4 @@ void SymbolTable::print(std::ostream& ss, int level) const { } } -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab diff --git a/src/symtab/symbol_table.hpp b/src/symtab/symbol_table.hpp index 9b64157f8a..dc2794bebb 100644 --- a/src/symtab/symbol_table.hpp +++ b/src/symtab/symbol_table.hpp @@ -21,8 +21,7 @@ #include "symtab/symbol.hpp" -namespace nmodl { -namespace symtab { +namespace nmodl::symtab { /** @@ -294,5 +293,4 @@ class ModelSymbolTable { /** @} */ // end of sym_tab -} // namespace symtab -} // namespace nmodl +} // namespace nmodl::symtab diff --git a/src/units/units.cpp b/src/units/units.cpp index 5f1465ab23..ed93a070a9 100644 --- a/src/units/units.cpp +++ b/src/units/units.cpp @@ -24,8 +24,7 @@ * \brief Units processing while being processed from lexer and parser */ -namespace nmodl { -namespace units { +namespace nmodl::units { Prefix::Prefix(std::string name, const std::string& factor) { if (name.back() == '-') { @@ -330,5 +329,4 @@ void UnitTable::print_base_units(std::ostream& base_units_details) const { base_units_details << '\n'; } -} // namespace units -} // namespace nmodl +} // namespace nmodl::units diff --git a/src/units/units.hpp b/src/units/units.hpp index 6c770bde79..7e78aad3b3 100644 --- a/src/units/units.hpp +++ b/src/units/units.hpp @@ -27,10 +27,8 @@ #include #include - -namespace nmodl { /// encapsulates unit database and tables implementation -namespace units { +namespace nmodl::units { /** * @defgroup units Unit Implementation @@ -292,5 +290,4 @@ class UnitTable { /** @} */ // end of units -} // namespace units -} // namespace nmodl +} // namespace nmodl::units diff --git a/src/utils/common_utils.cpp b/src/utils/common_utils.cpp index 9bcdeeb8f5..7d16827d35 100644 --- a/src/utils/common_utils.cpp +++ b/src/utils/common_utils.cpp @@ -22,8 +22,7 @@ #define IS_WINDOWS #endif -namespace nmodl { -namespace utils { +namespace nmodl::utils { std::string generate_random_string(const int len, UseNumbersInString use_numbers) { std::string s(len, 0); @@ -43,5 +42,4 @@ std::string generate_random_string(const int len, UseNumbersInString use_numbers return s; } -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/utils/common_utils.hpp b/src/utils/common_utils.hpp index 2508990917..be0eba7ede 100644 --- a/src/utils/common_utils.hpp +++ b/src/utils/common_utils.hpp @@ -24,9 +24,8 @@ * \brief Common utility functions for file/dir manipulation */ -namespace nmodl { /// file/string manipulation functions -namespace utils { +namespace nmodl::utils { /** * @defgroup utils Utility Implementation @@ -130,5 +129,4 @@ class SingletonRandomString { /** @} */ // end of utils -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/utils/perf_stat.cpp b/src/utils/perf_stat.cpp index 6156249ea7..ae3b4de051 100644 --- a/src/utils/perf_stat.cpp +++ b/src/utils/perf_stat.cpp @@ -12,8 +12,7 @@ #include "utils/perf_stat.hpp" #include "utils/table_data.hpp" -namespace nmodl { -namespace utils { +namespace nmodl::utils { PerfStat operator+(const PerfStat& first, const PerfStat& second) { PerfStat result; @@ -115,5 +114,4 @@ std::vector PerfStat::values() const { return row; } -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/utils/perf_stat.hpp b/src/utils/perf_stat.hpp index bcb76de474..c273afb12d 100644 --- a/src/utils/perf_stat.hpp +++ b/src/utils/perf_stat.hpp @@ -16,8 +16,7 @@ #include #include -namespace nmodl { -namespace utils { +namespace nmodl::utils { /** * @addtogroup utils @@ -108,5 +107,4 @@ struct PerfStat { /** @} */ // end of utils -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index 76a7c12506..dd60f75e91 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -12,8 +12,7 @@ #include #include -namespace nmodl { -namespace stringutils { +namespace nmodl::stringutils { std::string to_string(double value, const std::string& format_spec) { // double containing integer value @@ -27,5 +26,4 @@ std::string to_string(double value, const std::string& format_spec) { return fmt::format(format_spec, value); } -} // namespace stringutils -} // namespace nmodl +} // namespace nmodl::stringutils diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 749ee84c0f..a0176ec708 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -22,9 +22,8 @@ #include #include -namespace nmodl { /// string utility functions -namespace stringutils { +namespace nmodl::stringutils { /** * \addtogroup utils @@ -182,5 +181,4 @@ std::string to_string(double value, const std::string& format_spec = "{:.16g}"); /** \} */ // end of utils -} // namespace stringutils -} // namespace nmodl +} // namespace nmodl::stringutils diff --git a/src/utils/table_data.cpp b/src/utils/table_data.cpp index fd6c3b56a2..a6c17ca5f6 100644 --- a/src/utils/table_data.cpp +++ b/src/utils/table_data.cpp @@ -12,8 +12,7 @@ #include "utils/string_utils.hpp" #include "utils/table_data.hpp" -namespace nmodl { -namespace utils { +namespace nmodl::utils { /** * Print table data in below shown format: title as first row (centrally aligned), @@ -128,5 +127,4 @@ void TableData::print(int indent) const { print(std::cout, indent); } -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/utils/table_data.hpp b/src/utils/table_data.hpp index 7129a8c974..0f8adf35ed 100644 --- a/src/utils/table_data.hpp +++ b/src/utils/table_data.hpp @@ -18,8 +18,7 @@ #include "utils/string_utils.hpp" -namespace nmodl { -namespace utils { +namespace nmodl::utils { /** * @addtogroup utils @@ -55,5 +54,4 @@ struct TableData { /** @} */ // end of utils -} // namespace utils -} // namespace nmodl +} // namespace nmodl::utils diff --git a/src/visitors/after_cvode_to_cnexp_visitor.cpp b/src/visitors/after_cvode_to_cnexp_visitor.cpp index 13caa477ef..563bfa326c 100644 --- a/src/visitors/after_cvode_to_cnexp_visitor.cpp +++ b/src/visitors/after_cvode_to_cnexp_visitor.cpp @@ -13,8 +13,7 @@ #include "codegen/codegen_naming.hpp" #include "utils/logger.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void AfterCVodeToCnexpVisitor::visit_solve_block(ast::SolveBlock& node) { const auto& method = node.get_method(); @@ -27,5 +26,4 @@ void AfterCVodeToCnexpVisitor::visit_solve_block(ast::SolveBlock& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/after_cvode_to_cnexp_visitor.hpp b/src/visitors/after_cvode_to_cnexp_visitor.hpp index 182a01fb8b..33fdaad289 100644 --- a/src/visitors/after_cvode_to_cnexp_visitor.hpp +++ b/src/visitors/after_cvode_to_cnexp_visitor.hpp @@ -19,8 +19,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -50,5 +49,4 @@ class AfterCVodeToCnexpVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/constant_folder_visitor.cpp b/src/visitors/constant_folder_visitor.cpp index 69fab6bf25..970bf78cc2 100644 --- a/src/visitors/constant_folder_visitor.cpp +++ b/src/visitors/constant_folder_visitor.cpp @@ -12,8 +12,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /// check if given expression is a number /// note that the DEFINE node is already expanded to integer @@ -177,5 +176,4 @@ void ConstantFolderVisitor::visit_wrapped_expression(ast::WrappedExpression& nod logger->debug("ConstantFolderVisitor : expression {} folded to {}", nmodl_before, nmodl_after); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/constant_folder_visitor.hpp b/src/visitors/constant_folder_visitor.hpp index 6c9e735c53..2b97ffd0e5 100644 --- a/src/visitors/constant_folder_visitor.hpp +++ b/src/visitors/constant_folder_visitor.hpp @@ -22,8 +22,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -59,5 +58,4 @@ class ConstantFolderVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/defuse_analyze_visitor.cpp b/src/visitors/defuse_analyze_visitor.cpp index 7388d090de..66c0de2e04 100644 --- a/src/visitors/defuse_analyze_visitor.cpp +++ b/src/visitors/defuse_analyze_visitor.cpp @@ -13,8 +13,7 @@ #include "ast/all.hpp" #include "utils/logger.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using printer::JSONPrinter; using symtab::syminfo::NmodlType; @@ -444,5 +443,4 @@ DUChain DefUseAnalyzeVisitor::analyze(const ast::Ast& node, const std::string& n return usage; } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/defuse_analyze_visitor.hpp b/src/visitors/defuse_analyze_visitor.hpp index a36ac9e2f3..bf2eec918f 100644 --- a/src/visitors/defuse_analyze_visitor.hpp +++ b/src/visitors/defuse_analyze_visitor.hpp @@ -21,8 +21,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /// Represent a state in Def-Use chain enum class DUState { @@ -312,5 +311,4 @@ class DefUseAnalyzeVisitor: protected ConstAstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/global_var_visitor.cpp b/src/visitors/global_var_visitor.cpp index ae84720597..9b57c91647 100644 --- a/src/visitors/global_var_visitor.cpp +++ b/src/visitors/global_var_visitor.cpp @@ -17,8 +17,7 @@ #include "visitors/global_var_visitor.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void GlobalToRangeVisitor::visit_neuron_block(ast::NeuronBlock& node) { ast::RangeVarVector range_variables; @@ -65,5 +64,4 @@ void GlobalToRangeVisitor::visit_neuron_block(ast::NeuronBlock& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/global_var_visitor.hpp b/src/visitors/global_var_visitor.hpp index 8cecb5e4ce..73eebd793a 100644 --- a/src/visitors/global_var_visitor.hpp +++ b/src/visitors/global_var_visitor.hpp @@ -19,8 +19,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -87,5 +86,4 @@ class GlobalToRangeVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/implicit_argument_visitor.cpp b/src/visitors/implicit_argument_visitor.cpp index 14d84c1299..8fdc69330e 100644 --- a/src/visitors/implicit_argument_visitor.cpp +++ b/src/visitors/implicit_argument_visitor.cpp @@ -12,8 +12,7 @@ #include "codegen/codegen_naming.hpp" #include "lexer/token_mapping.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void ImplicitArgumentVisitor::visit_function_call(ast::FunctionCall& node) { auto function_name = node.get_node_name(); @@ -53,5 +52,4 @@ void ImplicitArgumentVisitor::visit_function_call(ast::FunctionCall& node) { node.visit_children(*this); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/implicit_argument_visitor.hpp b/src/visitors/implicit_argument_visitor.hpp index effca8793c..63be545cac 100644 --- a/src/visitors/implicit_argument_visitor.hpp +++ b/src/visitors/implicit_argument_visitor.hpp @@ -15,8 +15,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -38,5 +37,4 @@ struct ImplicitArgumentVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/indexedname_visitor.cpp b/src/visitors/indexedname_visitor.cpp index c039c52558..044d7fbf15 100644 --- a/src/visitors/indexedname_visitor.cpp +++ b/src/visitors/indexedname_visitor.cpp @@ -9,8 +9,7 @@ #include "ast/binary_expression.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void IndexedNameVisitor::visit_indexed_name(ast::IndexedName& node) { indexed_name = nmodl::get_indexed_name(node); @@ -34,5 +33,4 @@ std::string IndexedNameVisitor::get_indexed_name() { return indexed_name; } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/indexedname_visitor.hpp b/src/visitors/indexedname_visitor.hpp index 9d38b6db33..81e2134fcb 100644 --- a/src/visitors/indexedname_visitor.hpp +++ b/src/visitors/indexedname_visitor.hpp @@ -20,8 +20,7 @@ #include "ast/program.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -64,5 +63,4 @@ class IndexedNameVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/inline_visitor.cpp b/src/visitors/inline_visitor.cpp index 5820ddd2a4..81563a645e 100644 --- a/src/visitors/inline_visitor.cpp +++ b/src/visitors/inline_visitor.cpp @@ -16,8 +16,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using namespace ast; @@ -326,5 +325,4 @@ void InlineVisitor::visit_program(Program& node) { node.visit_children(*this); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/inline_visitor.hpp b/src/visitors/inline_visitor.hpp index 9a728da04b..84659c1a26 100644 --- a/src/visitors/inline_visitor.hpp +++ b/src/visitors/inline_visitor.hpp @@ -18,8 +18,7 @@ #include "symtab/decl.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -198,5 +197,4 @@ class InlineVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/kinetic_block_visitor.cpp b/src/visitors/kinetic_block_visitor.cpp index 69a317a3b3..4fd2ac0a9f 100644 --- a/src/visitors/kinetic_block_visitor.cpp +++ b/src/visitors/kinetic_block_visitor.cpp @@ -14,8 +14,7 @@ #include "visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using symtab::syminfo::NmodlType; @@ -489,5 +488,4 @@ void KineticBlockVisitor::visit_program(ast::Program& node) { node.set_blocks(std::move(blocks)); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/kinetic_block_visitor.hpp b/src/visitors/kinetic_block_visitor.hpp index 0f67260594..9ae057aef0 100644 --- a/src/visitors/kinetic_block_visitor.hpp +++ b/src/visitors/kinetic_block_visitor.hpp @@ -20,8 +20,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -151,5 +150,4 @@ class KineticBlockVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/local_to_assigned_visitor.cpp b/src/visitors/local_to_assigned_visitor.cpp index 89f7734899..00e87b975a 100644 --- a/src/visitors/local_to_assigned_visitor.cpp +++ b/src/visitors/local_to_assigned_visitor.cpp @@ -15,8 +15,7 @@ #include "visitors/local_to_assigned_visitor.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void LocalToAssignedVisitor::visit_program(ast::Program& node) { ast::AssignedDefinitionVector assigned_variables; @@ -81,5 +80,4 @@ void LocalToAssignedVisitor::visit_program(ast::Program& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/local_to_assigned_visitor.hpp b/src/visitors/local_to_assigned_visitor.hpp index 4e757718ef..b68b592300 100644 --- a/src/visitors/local_to_assigned_visitor.hpp +++ b/src/visitors/local_to_assigned_visitor.hpp @@ -14,8 +14,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -79,5 +78,4 @@ class LocalToAssignedVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/local_var_rename_visitor.cpp b/src/visitors/local_var_rename_visitor.cpp index a93a1128a6..1e9322a843 100644 --- a/src/visitors/local_var_rename_visitor.cpp +++ b/src/visitors/local_var_rename_visitor.cpp @@ -14,8 +14,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using symtab::SymbolTable; @@ -75,5 +74,4 @@ void LocalVarRenameVisitor::visit_statement_block(ast::StatementBlock& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/local_var_rename_visitor.hpp b/src/visitors/local_var_rename_visitor.hpp index a73196e194..2af0c67d91 100644 --- a/src/visitors/local_var_rename_visitor.hpp +++ b/src/visitors/local_var_rename_visitor.hpp @@ -18,8 +18,7 @@ #include "symtab/decl.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -77,5 +76,4 @@ class LocalVarRenameVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/localize_visitor.cpp b/src/visitors/localize_visitor.cpp index 0181940b57..071aebe4fb 100644 --- a/src/visitors/localize_visitor.cpp +++ b/src/visitors/localize_visitor.cpp @@ -14,8 +14,7 @@ #include "utils/logger.hpp" #include "visitors/defuse_analyze_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using symtab::Symbol; using symtab::syminfo::NmodlType; @@ -159,5 +158,4 @@ void LocalizeVisitor::visit_program(const ast::Program& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/localize_visitor.hpp b/src/visitors/localize_visitor.hpp index 821e072fe2..577f3580c2 100644 --- a/src/visitors/localize_visitor.hpp +++ b/src/visitors/localize_visitor.hpp @@ -18,8 +18,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -104,5 +103,4 @@ class LocalizeVisitor: public ConstAstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/loop_unroll_visitor.cpp b/src/visitors/loop_unroll_visitor.cpp index 35697f19be..f93d681733 100644 --- a/src/visitors/loop_unroll_visitor.cpp +++ b/src/visitors/loop_unroll_visitor.cpp @@ -13,8 +13,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \class IndexRemover @@ -130,7 +129,7 @@ static std::shared_ptr unroll_for_loop( } /// create new statement representing unrolled loop - auto block = new ast::StatementBlock(std::move(statements)); + auto block = std::make_shared(statements); return std::make_shared(block); } @@ -167,5 +166,4 @@ void LoopUnrollVisitor::visit_statement_block(ast::StatementBlock& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/loop_unroll_visitor.hpp b/src/visitors/loop_unroll_visitor.hpp index 054dfb89b9..9d2f464a6e 100644 --- a/src/visitors/loop_unroll_visitor.hpp +++ b/src/visitors/loop_unroll_visitor.hpp @@ -16,8 +16,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -65,5 +64,4 @@ class LoopUnrollVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/neuron_solve_visitor.cpp b/src/visitors/neuron_solve_visitor.cpp index d8da1e03c2..435e19bbe6 100644 --- a/src/visitors/neuron_solve_visitor.cpp +++ b/src/visitors/neuron_solve_visitor.cpp @@ -15,8 +15,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void NeuronSolveVisitor::visit_solve_block(ast::SolveBlock& node) { auto name = node.get_block_name()->get_node_name(); @@ -115,5 +114,4 @@ void NeuronSolveVisitor::visit_program(ast::Program& node) { node.visit_children(*this); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/neuron_solve_visitor.hpp b/src/visitors/neuron_solve_visitor.hpp index 85029ed43e..e1b14b3c37 100644 --- a/src/visitors/neuron_solve_visitor.hpp +++ b/src/visitors/neuron_solve_visitor.hpp @@ -19,8 +19,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup solver @@ -73,5 +72,4 @@ class NeuronSolveVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/perf_visitor.cpp b/src/visitors/perf_visitor.cpp index 078c8300e0..216518d699 100644 --- a/src/visitors/perf_visitor.cpp +++ b/src/visitors/perf_visitor.cpp @@ -13,8 +13,7 @@ #include "printer/json_printer.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using printer::JSONPrinter; using symtab::Symbol; @@ -577,5 +576,4 @@ void PerfVisitor::update_memory_ops(const std::string& name) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/perf_visitor.hpp b/src/visitors/perf_visitor.hpp index 7fa0c01d3f..8b44318151 100644 --- a/src/visitors/perf_visitor.hpp +++ b/src/visitors/perf_visitor.hpp @@ -22,8 +22,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -253,5 +252,4 @@ class PerfVisitor: public ConstAstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/rename_visitor.cpp b/src/visitors/rename_visitor.cpp index 0328d01417..4e1857f825 100644 --- a/src/visitors/rename_visitor.cpp +++ b/src/visitors/rename_visitor.cpp @@ -13,8 +13,7 @@ #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { std::string RenameVisitor::new_name_generator(const std::string& old_name) { @@ -101,5 +100,4 @@ void RenameVisitor::visit_verbatim(const ast::Verbatim& node) { statement->set(result.str()); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/rename_visitor.hpp b/src/visitors/rename_visitor.hpp index 3bd62fb016..bb8fcdf14d 100644 --- a/src/visitors/rename_visitor.hpp +++ b/src/visitors/rename_visitor.hpp @@ -19,8 +19,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -110,5 +109,4 @@ class RenameVisitor: public ConstAstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/semantic_analysis_visitor.cpp b/src/visitors/semantic_analysis_visitor.cpp index 40d6b1667b..571ec4ef59 100644 --- a/src/visitors/semantic_analysis_visitor.cpp +++ b/src/visitors/semantic_analysis_visitor.cpp @@ -18,8 +18,7 @@ #include "utils/logger.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { bool SemanticAnalysisVisitor::check(const ast::Program& node) { check_fail = false; @@ -170,5 +169,4 @@ void SemanticAnalysisVisitor::visit_mutex_unlock(const ast::MutexUnlock& /* node /// --> } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/semantic_analysis_visitor.hpp b/src/visitors/semantic_analysis_visitor.hpp index 1deffcb154..4c43e10ba1 100644 --- a/src/visitors/semantic_analysis_visitor.hpp +++ b/src/visitors/semantic_analysis_visitor.hpp @@ -35,8 +35,7 @@ #include "ast/ast.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { class SemanticAnalysisVisitor: public ConstAstVisitor { private: @@ -90,5 +89,4 @@ class SemanticAnalysisVisitor: public ConstAstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/solve_block_visitor.cpp b/src/visitors/solve_block_visitor.cpp index 7355789ad4..2a1d0f71a6 100644 --- a/src/visitors/solve_block_visitor.cpp +++ b/src/visitors/solve_block_visitor.cpp @@ -14,8 +14,7 @@ #include "codegen/codegen_naming.hpp" #include "visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void SolveBlockVisitor::visit_breakpoint_block(ast::BreakpointBlock& node) { in_breakpoint_block = true; @@ -93,5 +92,4 @@ void SolveBlockVisitor::visit_program(ast::Program& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/solve_block_visitor.hpp b/src/visitors/solve_block_visitor.hpp index a22509d130..e10763b53b 100644 --- a/src/visitors/solve_block_visitor.hpp +++ b/src/visitors/solve_block_visitor.hpp @@ -15,8 +15,7 @@ #include "symtab/decl.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -52,5 +51,4 @@ class SolveBlockVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/steadystate_visitor.cpp b/src/visitors/steadystate_visitor.cpp index 4c69600d1f..c2b426ebf8 100644 --- a/src/visitors/steadystate_visitor.cpp +++ b/src/visitors/steadystate_visitor.cpp @@ -12,8 +12,7 @@ #include "utils/logger.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { std::shared_ptr SteadystateVisitor::create_steadystate_block( const std::shared_ptr& solve_block, @@ -105,5 +104,4 @@ void SteadystateVisitor::visit_program(ast::Program& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/steadystate_visitor.hpp b/src/visitors/steadystate_visitor.hpp index 6b4e3432ad..55ffc28ef6 100644 --- a/src/visitors/steadystate_visitor.hpp +++ b/src/visitors/steadystate_visitor.hpp @@ -14,8 +14,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -69,5 +68,4 @@ class SteadystateVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_conductance_visitor.cpp b/src/visitors/sympy_conductance_visitor.cpp index 30aa9bfd4e..593a2edfc5 100644 --- a/src/visitors/sympy_conductance_visitor.cpp +++ b/src/visitors/sympy_conductance_visitor.cpp @@ -17,8 +17,7 @@ namespace pywrap = nmodl::pybind_wrappers; -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using ast::AstNodeType; using ast::BinaryOp; @@ -244,5 +243,4 @@ void SympyConductanceVisitor::visit_program(ast::Program& node) { node.visit_children(*this); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_conductance_visitor.hpp b/src/visitors/sympy_conductance_visitor.hpp index cb76bdf2fd..e891f87d85 100644 --- a/src/visitors/sympy_conductance_visitor.hpp +++ b/src/visitors/sympy_conductance_visitor.hpp @@ -18,9 +18,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { - -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -101,5 +99,4 @@ class SympyConductanceVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_replace_solutions_visitor.cpp b/src/visitors/sympy_replace_solutions_visitor.cpp index 9906c5577e..5aaf9dcc13 100644 --- a/src/visitors/sympy_replace_solutions_visitor.cpp +++ b/src/visitors/sympy_replace_solutions_visitor.cpp @@ -12,8 +12,7 @@ #include "utils/logger.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \details SympyReplaceSolutionsVisitor tells us that a new equation appear and, depending where @@ -462,5 +461,4 @@ void SympyReplaceSolutionsVisitor::StatementDispenser::tag_all_statements() { } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_replace_solutions_visitor.hpp b/src/visitors/sympy_replace_solutions_visitor.hpp index 42bc4da2d0..d3b7e95983 100644 --- a/src/visitors/sympy_replace_solutions_visitor.hpp +++ b/src/visitors/sympy_replace_solutions_visitor.hpp @@ -21,8 +21,7 @@ #include #include -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -498,5 +497,4 @@ class SympyReplaceSolutionsVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_solver_visitor.cpp b/src/visitors/sympy_solver_visitor.cpp index 040bddbc69..061b8d7819 100644 --- a/src/visitors/sympy_solver_visitor.cpp +++ b/src/visitors/sympy_solver_visitor.cpp @@ -19,8 +19,7 @@ namespace pywrap = nmodl::pybind_wrappers; -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using symtab::syminfo::NmodlType; @@ -682,5 +681,4 @@ void SympySolverVisitor::visit_program(ast::Program& node) { node.visit_children(*this); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/sympy_solver_visitor.hpp b/src/visitors/sympy_solver_visitor.hpp index b5a5b13516..4033d86174 100644 --- a/src/visitors/sympy_solver_visitor.hpp +++ b/src/visitors/sympy_solver_visitor.hpp @@ -23,8 +23,7 @@ #include "visitors/ast_visitor.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -187,5 +186,4 @@ class SympySolverVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/symtab_visitor_helper.hpp b/src/visitors/symtab_visitor_helper.hpp index cfe299d64e..5298889477 100644 --- a/src/visitors/symtab_visitor_helper.hpp +++ b/src/visitors/symtab_visitor_helper.hpp @@ -15,8 +15,7 @@ #include "visitors/symtab_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { using symtab::Symbol; using symtab::syminfo::NmodlType; @@ -261,5 +260,4 @@ void SymtabVisitor::visit_table_statement(ast::TableStatement& node) { update_symbol(node.get_depend_vars(), NmodlType::table_assigned_var, num_values); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/units_visitor.cpp b/src/visitors/units_visitor.cpp index 2ad612d0ea..ca09641751 100644 --- a/src/visitors/units_visitor.cpp +++ b/src/visitors/units_visitor.cpp @@ -16,8 +16,7 @@ * by the Units Parser used to parse the \c nrnunits.lib file */ -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void UnitsVisitor::visit_program(ast::Program& node) { units_driver.parse_file(units_dir); @@ -134,5 +133,4 @@ void UnitsVisitor::visit_factor_def(ast::FactorDef& node) { } } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/units_visitor.hpp b/src/visitors/units_visitor.hpp index 543b0655a0..a987ca1c47 100644 --- a/src/visitors/units_visitor.hpp +++ b/src/visitors/units_visitor.hpp @@ -20,8 +20,7 @@ #include "visitors/ast_visitor.hpp" #include "visitors/visitor_utils.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -87,5 +86,4 @@ class UnitsVisitor: public AstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/var_usage_visitor.cpp b/src/visitors/var_usage_visitor.cpp index 5f355400da..932e756cc8 100644 --- a/src/visitors/var_usage_visitor.cpp +++ b/src/visitors/var_usage_visitor.cpp @@ -12,8 +12,7 @@ #include "ast/name.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /// rename matching variable void VarUsageVisitor::visit_name(const ast::Name& node) { @@ -30,5 +29,4 @@ bool VarUsageVisitor::variable_used(const ast::Node& node, std::string name) { return used; } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/var_usage_visitor.hpp b/src/visitors/var_usage_visitor.hpp index 933f3b5f0f..0ceca7d5ca 100644 --- a/src/visitors/var_usage_visitor.hpp +++ b/src/visitors/var_usage_visitor.hpp @@ -17,8 +17,7 @@ #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * \addtogroup visitor_classes @@ -48,5 +47,4 @@ class VarUsageVisitor: protected ConstAstVisitor { /** \} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/verbatim_var_rename_visitor.cpp b/src/visitors/verbatim_var_rename_visitor.cpp index 3908a88679..49e3f923b3 100644 --- a/src/visitors/verbatim_var_rename_visitor.cpp +++ b/src/visitors/verbatim_var_rename_visitor.cpp @@ -14,8 +14,7 @@ #include "src/utils/logger.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void VerbatimVarRenameVisitor::visit_statement_block(ast::StatementBlock& node) { if (node.get_statements().empty()) { @@ -93,5 +92,4 @@ void VerbatimVarRenameVisitor::visit_verbatim(ast::Verbatim& node) { statement->set(oss.str()); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/verbatim_var_rename_visitor.hpp b/src/visitors/verbatim_var_rename_visitor.hpp index 81baddb3fd..0077c44542 100644 --- a/src/visitors/verbatim_var_rename_visitor.hpp +++ b/src/visitors/verbatim_var_rename_visitor.hpp @@ -18,8 +18,7 @@ #include "symtab/symbol_table.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -72,5 +71,4 @@ class VerbatimVarRenameVisitor: public AstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/verbatim_visitor.cpp b/src/visitors/verbatim_visitor.cpp index a9c540b15f..da186ef46d 100644 --- a/src/visitors/verbatim_visitor.cpp +++ b/src/visitors/verbatim_visitor.cpp @@ -12,8 +12,7 @@ #include "ast/string.hpp" #include "ast/verbatim.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { void VerbatimVisitor::visit_verbatim(const ast::Verbatim& node) { std::string block; @@ -28,5 +27,4 @@ void VerbatimVisitor::visit_verbatim(const ast::Verbatim& node) { blocks.push_back(block); } -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/src/visitors/verbatim_visitor.hpp b/src/visitors/verbatim_visitor.hpp index d17c06b5dd..180322366a 100644 --- a/src/visitors/verbatim_visitor.hpp +++ b/src/visitors/verbatim_visitor.hpp @@ -17,8 +17,7 @@ #include "ast/ast.hpp" #include "visitors/ast_visitor.hpp" -namespace nmodl { -namespace visitor { +namespace nmodl::visitor { /** * @addtogroup visitor_classes @@ -59,5 +58,4 @@ class VerbatimVisitor: public ConstAstVisitor { /** @} */ // end of visitor_classes -} // namespace visitor -} // namespace nmodl +} // namespace nmodl::visitor diff --git a/test/unit/codegen/codegen_compatibility_visitor.cpp b/test/unit/codegen/codegen_compatibility_visitor.cpp index 5e686498f0..141f4a1ae0 100644 --- a/test/unit/codegen/codegen_compatibility_visitor.cpp +++ b/test/unit/codegen/codegen_compatibility_visitor.cpp @@ -8,7 +8,6 @@ #include #include -#include "ast/program.hpp" #include "codegen/codegen_compatibility_visitor.hpp" #include "parser/nmodl_driver.hpp" #include "test/unit/utils/test_utils.hpp" @@ -31,7 +30,7 @@ bool runCompatibilityVisitor(const std::string& nmodl_text) { return CodegenCompatibilityVisitor().find_unhandled_ast_nodes(*ast); } -SCENARIO("Uncompatible constructs should failed", "[codegen][compatibility_visitor]") { +SCENARIO("Incompatible constructs should failed", "[codegen][compatibility_visitor]") { GIVEN("A mod file containing an EXTERNAL construct") { std::string const nmodl_text = R"( NEURON { diff --git a/test/unit/codegen/codegen_cpp_visitor.cpp b/test/unit/codegen/codegen_cpp_visitor.cpp index 967c5d3267..fae23c26c4 100644 --- a/test/unit/codegen/codegen_cpp_visitor.cpp +++ b/test/unit/codegen/codegen_cpp_visitor.cpp @@ -11,7 +11,6 @@ #include "ast/program.hpp" #include "codegen/codegen_acc_visitor.hpp" #include "codegen/codegen_cpp_visitor.hpp" -#include "codegen/codegen_helper_visitor.hpp" #include "parser/nmodl_driver.hpp" #include "test/unit/utils/test_utils.hpp" #include "visitors/implicit_argument_visitor.hpp" @@ -299,7 +298,7 @@ SCENARIO("Check instance variable definition order", "[codegen][var_order]") { } } -std::string get_instance_structure(std::string nmodl_text) { +std::string get_instance_structure(const std::string& nmodl_text) { // parse mod file & print mechanism structure auto const ast = NmodlDriver{}.parse_string(nmodl_text); // add implicit arguments @@ -535,8 +534,7 @@ SCENARIO("Check that BEFORE/AFTER block are well generated", "[codegen][before/a inc = inc + 1.0; } })"; - auto const expected = generated_code; - REQUIRE_THAT(generated, ContainsSubstring(expected)); + REQUIRE_THAT(generated, ContainsSubstring(generated_code)); } // AFTER SOLVE { @@ -560,8 +558,7 @@ SCENARIO("Check that BEFORE/AFTER block are well generated", "[codegen][before/a } } })"; - auto const expected = generated_code; - REQUIRE_THAT(generated, ContainsSubstring(expected)); + REQUIRE_THAT(generated, ContainsSubstring(generated_code)); } // BEFORE INITIAL { @@ -582,8 +579,7 @@ SCENARIO("Check that BEFORE/AFTER block are well generated", "[codegen][before/a inc = 0.0; } })"; - auto const expected = generated_code; - REQUIRE_THAT(generated, ContainsSubstring(expected)); + REQUIRE_THAT(generated, ContainsSubstring(generated_code)); } // AFTER INITIAL { @@ -604,8 +600,7 @@ SCENARIO("Check that BEFORE/AFTER block are well generated", "[codegen][before/a inc = 0.0; } })"; - auto const expected = generated_code; - REQUIRE_THAT(generated, ContainsSubstring(expected)); + REQUIRE_THAT(generated, ContainsSubstring(generated_code)); } // BEFORE STEP { @@ -626,8 +621,7 @@ SCENARIO("Check that BEFORE/AFTER block are well generated", "[codegen][before/a inc = 0.0; } })"; - auto const expected = generated_code; - REQUIRE_THAT(generated, ContainsSubstring(expected)); + REQUIRE_THAT(generated, ContainsSubstring(generated_code)); } } }