Skip to content

Commit

Permalink
Lower printing of VERBATIM code. (#1543)
Browse files Browse the repository at this point in the history
Lower all of `process_verbatim_text` and the implementation
of `visit_verbatim` to the CoreNEURON visitor. The NEURON
version will use a different system.
1uc authored Oct 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e74ebce commit d4a43e9
Showing 6 changed files with 21 additions and 39 deletions.
15 changes: 15 additions & 0 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
@@ -118,6 +118,21 @@ std::string CodegenCoreneuronCppVisitor::process_verbatim_token(const std::strin
return get_variable_name(token, use_instance);
}

void CodegenCoreneuronCppVisitor::visit_verbatim(const Verbatim& node) {
const auto& text = node.get_statement()->eval();
printer->add_line("// VERBATIM");
const auto& result = process_verbatim_text(text);

const auto& statements = stringutils::split_string(result, '\n');
for (const auto& statement: statements) {
const auto& trimed_stmt = stringutils::trim_newline(statement);
if (trimed_stmt.find_first_not_of(' ') != std::string::npos) {
printer->add_line(trimed_stmt);
}
}
printer->add_line("// ENDVERBATIM");
}


/**
* \details This can be override in the backend. For example, parameters can be constant
3 changes: 2 additions & 1 deletion src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
@@ -408,7 +408,7 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
* \param text The verbatim code to be processed
* \return The code with all variables renamed as needed
*/
std::string process_verbatim_text(std::string const& text) override;
std::string process_verbatim_text(std::string const& text);


/**
@@ -947,6 +947,7 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {

void visit_derivimplicit_callback(const ast::DerivimplicitCallback& node) override;
void visit_for_netcon(const ast::ForNetcon& node) override;
void visit_verbatim(const ast::Verbatim& node) override;
void visit_watch_statement(const ast::WatchStatement& node) override;

ParamVector functor_params() override;
16 changes: 0 additions & 16 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
@@ -1084,22 +1084,6 @@ void CodegenCppVisitor::visit_function_call(const FunctionCall& node) {
}


void CodegenCppVisitor::visit_verbatim(const Verbatim& node) {
const auto& text = node.get_statement()->eval();
printer->add_line("// VERBATIM");
const auto& result = process_verbatim_text(text);

const auto& statements = stringutils::split_string(result, '\n');
for (const auto& statement: statements) {
const auto& trimed_stmt = stringutils::trim_newline(statement);
if (trimed_stmt.find_first_not_of(' ') != std::string::npos) {
printer->add_line(trimed_stmt);
}
}
printer->add_line("// ENDVERBATIM");
}


void CodegenCppVisitor::visit_update_dt(const ast::UpdateDt& node) {
// dt change statement should be pulled outside already
}
9 changes: 0 additions & 9 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
@@ -1050,14 +1050,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
*/
virtual std::string nrn_thread_internal_arguments() = 0;

/**
* Process a verbatim block for possible variable renaming
* \param text The verbatim code to be processed
* \return The code with all variables renamed as needed
*/
virtual std::string process_verbatim_text(std::string const& text) = 0;


/**
* Arguments for register_mech or point_register_mech function
*/
@@ -1497,7 +1489,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
void visit_unary_operator(const ast::UnaryOperator& node) override;
void visit_unit(const ast::Unit& node) override;
void visit_var_name(const ast::VarName& node) override;
void visit_verbatim(const ast::Verbatim& node) override;
void visit_while_statement(const ast::WhileStatement& node) override;
void visit_update_dt(const ast::UpdateDt& node) override;
void visit_protect_statement(const ast::ProtectStatement& node) override;
6 changes: 3 additions & 3 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
@@ -631,9 +631,9 @@ CodegenNeuronCppVisitor::function_table_parameters(const ast::FunctionTableBlock
return {params, {}};
}

/// TODO: Write for NEURON
std::string CodegenNeuronCppVisitor::process_verbatim_text(std::string const& text) {
return {};

void CodegenNeuronCppVisitor::visit_verbatim(const Verbatim& node) {
// Not implemented yet.
}


11 changes: 1 addition & 10 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
@@ -358,14 +358,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
const ast::FunctionTableBlock& /* node */) override;


/**
* Process a verbatim block for possible variable renaming
* \param text The verbatim code to be processed
* \return The code with all variables renamed as needed
*/
std::string process_verbatim_text(std::string const& text) override;


/**
* Arguments for register_mech or point_register_mech function
*/
@@ -768,13 +760,12 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
/* Overloaded visitor routines */
/****************************************************************************************/


void visit_verbatim(const ast::Verbatim& node) override;
void visit_watch_statement(const ast::WatchStatement& node) override;
void visit_for_netcon(const ast::ForNetcon& node) override;
void visit_longitudinal_diffusion_block(const ast::LongitudinalDiffusionBlock& node) override;
void visit_lon_diffuse(const ast::LonDiffuse& node) override;


public:
/****************************************************************************************/
/* Public printing routines for code generation for use in unit tests */

0 comments on commit d4a43e9

Please sign in to comment.