From a30f4dd4a1ef56c962ea84fa06eff0e459ae59df Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 8 Dec 2023 09:38:28 +0100 Subject: [PATCH] Move `print_function_call`. Additionally, adds stubs for `print_net_{send,move,event}_call` to `CodegenNeuronCppVisitor`. --- .../codegen_coreneuron_cpp_visitor.cpp | 37 ------------------- .../codegen_coreneuron_cpp_visitor.hpp | 13 ++----- src/codegen/codegen_cpp_visitor.cpp | 36 ++++++++++++++++++ src/codegen/codegen_cpp_visitor.hpp | 21 ++++++++++- src/codegen/codegen_neuron_cpp_visitor.cpp | 18 ++++++--- src/codegen/codegen_neuron_cpp_visitor.hpp | 20 ++++++++-- 6 files changed, 88 insertions(+), 57 deletions(-) diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.cpp b/src/codegen/codegen_coreneuron_cpp_visitor.cpp index 126921c35b..bf22efb29c 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.cpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.cpp @@ -507,43 +507,6 @@ void CodegenCoreneuronCppVisitor::print_global_var_struct_decl() { /****************************************************************************************/ -void CodegenCoreneuronCppVisitor::print_function_call(const FunctionCall& node) { - const auto& name = node.get_node_name(); - auto function_name = name; - if (defined_method(name)) { - function_name = method_name(name); - } - - if (is_net_send(name)) { - print_net_send_call(node); - return; - } - - if (is_net_move(name)) { - print_net_move_call(node); - return; - } - - if (is_net_event(name)) { - print_net_event_call(node); - return; - } - - const auto& arguments = node.get_arguments(); - printer->add_text(function_name, '('); - - if (defined_method(name)) { - printer->add_text(internal_method_arguments()); - if (!arguments.empty()) { - printer->add_text(", "); - } - } - - print_vector_elements(arguments, ", "); - printer->add_text(')'); -} - - void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() { if (info.top_verbatim_blocks.empty()) { return; diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.hpp b/src/codegen/codegen_coreneuron_cpp_visitor.hpp index f411e18366..5693cb245f 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.hpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.hpp @@ -421,13 +421,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor { /****************************************************************************************/ - /** - * Print call to internal or external function - * \param node The AST node representing a function call - */ - void print_function_call(const ast::FunctionCall& node) override; - - /** * Print top level (global scope) verbatim blocks */ @@ -951,21 +944,21 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor { * Print call to \c net\_send * \param node The AST node representing the function call */ - void print_net_send_call(const ast::FunctionCall& node); + void print_net_send_call(const ast::FunctionCall& node) override; /** * Print call to net\_move * \param node The AST node representing the function call */ - void print_net_move_call(const ast::FunctionCall& node); + void print_net_move_call(const ast::FunctionCall& node) override; /** * Print call to net\_event * \param node The AST node representing the function call */ - void print_net_event_call(const ast::FunctionCall& node); + void print_net_event_call(const ast::FunctionCall& node) override; /** diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index 779d045a7b..0f09ba81f4 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -214,6 +214,42 @@ bool CodegenCppVisitor::need_semicolon(const Statement& node) { /* Main printing routines for code generation */ /****************************************************************************************/ +void CodegenCppVisitor::print_function_call(const FunctionCall& node) { + const auto& name = node.get_node_name(); + auto function_name = name; + if (defined_method(name)) { + function_name = method_name(name); + } + + if (is_net_send(name)) { + print_net_send_call(node); + return; + } + + if (is_net_move(name)) { + print_net_move_call(node); + return; + } + + if (is_net_event(name)) { + print_net_event_call(node); + return; + } + + const auto& arguments = node.get_arguments(); + printer->add_text(function_name, '('); + + if (defined_method(name)) { + printer->add_text(internal_method_arguments()); + if (!arguments.empty()) { + printer->add_text(", "); + } + } + + print_vector_elements(arguments, ", "); + printer->add_text(')'); +} + void CodegenCppVisitor::print_prcellstate_macros() const { printer->add_line("#ifndef NRN_PRCELLSTATE"); diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index b611aec9e7..7f46826c99 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -607,8 +607,27 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { * Print call to internal or external function * \param node The AST node representing a function call */ - virtual void print_function_call(const ast::FunctionCall& node) = 0; + virtual void print_function_call(const ast::FunctionCall& node); + /** + * Print call to \c net\_send + * \param node The AST node representing the function call + */ + virtual void print_net_send_call(const ast::FunctionCall& node) = 0; + + + /** + * Print call to net\_move + * \param node The AST node representing the function call + */ + virtual void print_net_move_call(const ast::FunctionCall& node) = 0; + + + /** + * Print call to net\_event + * \param node The AST node representing the function call + */ + virtual void print_net_event_call(const ast::FunctionCall& node) = 0; /** * Print function and procedures prototype declaration diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index d73b89d6e9..bddd2ae3dc 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -89,12 +89,6 @@ void CodegenNeuronCppVisitor::print_atomic_reduction_pragma() { /****************************************************************************************/ -/// TODO: Edit for NEURON -void CodegenNeuronCppVisitor::print_function_call(const FunctionCall& node) { - return; -} - - /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_function_prototypes() { if (info.functions.empty() && info.procedures.empty()) { @@ -743,6 +737,18 @@ void CodegenNeuronCppVisitor::print_codegen_routines() { codegen = false; } +void CodegenNeuronCppVisitor::print_net_send_call(const ast::FunctionCall& node) { + throw std::runtime_error("Not implemented."); +} + +void CodegenNeuronCppVisitor::print_net_move_call(const ast::FunctionCall& node) { + throw std::runtime_error("Not implemented."); +} + +void CodegenNeuronCppVisitor::print_net_event_call(const ast::FunctionCall& node) { + throw std::runtime_error("Not implemented."); +} + /****************************************************************************************/ /* Overloaded visitor routines */ diff --git a/src/codegen/codegen_neuron_cpp_visitor.hpp b/src/codegen/codegen_neuron_cpp_visitor.hpp index 6d7bf0f1f3..e44f30f238 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.hpp +++ b/src/codegen/codegen_neuron_cpp_visitor.hpp @@ -122,10 +122,24 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor { /** - * Print call to internal or external function - * \param node The AST node representing a function call + * Print call to \c net\_send + * \param node The AST node representing the function call */ - void print_function_call(const ast::FunctionCall& node) override; + void print_net_send_call(const ast::FunctionCall& node) override; + + + /** + * Print call to net\_move + * \param node The AST node representing the function call + */ + void print_net_move_call(const ast::FunctionCall& node) override; + + + /** + * Print call to net\_event + * \param node The AST node representing the function call + */ + void print_net_event_call(const ast::FunctionCall& node) override; /**