Skip to content

Commit

Permalink
Refactor print_namespace_{start,stop}.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Jul 30, 2024
1 parent 02101b2 commit 41085b6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 40 deletions.
13 changes: 3 additions & 10 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() {
print_namespace_stop();

printer->add_newline(2);
printer->add_line("using namespace coreneuron;");
print_using_namespace();

printing_top_verbatim_blocks = true;

Expand Down Expand Up @@ -767,17 +767,10 @@ void CodegenCoreneuronCppVisitor::print_memb_list_getter() {
}


void CodegenCoreneuronCppVisitor::print_namespace_start() {
printer->add_newline(2);
printer->push_block("namespace coreneuron");
}


void CodegenCoreneuronCppVisitor::print_namespace_stop() {
printer->pop_block();
std::string CodegenCoreneuronCppVisitor::namespace_name() {
return "coreneuron";
}


/**
* \details There are three types of thread variables currently considered:
* - top local thread variables
Expand Down
11 changes: 1 addition & 10 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,7 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
void print_memb_list_getter();


/**
* Prints the start of the \c coreneuron namespace
*/
void print_namespace_start() override;


/**
* Prints the end of the \c coreneuron namespace
*/
void print_namespace_stop() override;
virtual std::string namespace_name() override;


/**
Expand Down
14 changes: 14 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,20 @@ void CodegenCppVisitor::print_mechanism_info() {
printer->add_line("};");
}

void CodegenCppVisitor::print_using_namespace() {
printer->fmt_line("using namespace {}", namespace_name());
}

void CodegenCppVisitor::print_namespace_start() {
printer->add_newline(2);
printer->fmt_push_block("namespace {}", namespace_name());
}


void CodegenCppVisitor::print_namespace_stop() {
printer->pop_block();
}


/****************************************************************************************/
/* Printing routines for code generation */
Expand Down
11 changes: 9 additions & 2 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,18 +1072,25 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
/* Code-specific printing routines for code generations */
/****************************************************************************************/

/** Name of "our" namespace.
*/
virtual std::string namespace_name() = 0;

/**
* Prints the start of the simulator namespace
*/
virtual void print_namespace_start() = 0;
void print_namespace_start();


/**
* Prints the end of the simulator namespace
*/
virtual void print_namespace_stop() = 0;
void print_namespace_stop();

/**
* Prints f"using namespace {namespace_name()}".
*/
void print_using_namespace();

/****************************************************************************************/
/* Routines for returning variable name */
Expand Down
10 changes: 2 additions & 8 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,11 @@ std::string CodegenNeuronCppVisitor::py_function_signature(
/* Code-specific printing routines for code generation */
/****************************************************************************************/


void CodegenNeuronCppVisitor::print_namespace_start() {
printer->add_newline(2);
printer->push_block("namespace neuron");
std::string CodegenNeuronCppVisitor::namespace_name() {
return "neuron";
}


void CodegenNeuronCppVisitor::print_namespace_stop() {
printer->pop_block();
}

void CodegenNeuronCppVisitor::append_conc_write_statements(
std::vector<ShadowUseStatement>& statements,
const Ion& ion,
Expand Down
11 changes: 1 addition & 10 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,7 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
/****************************************************************************************/


/**
* Prints the start of the \c neuron namespace
*/
void print_namespace_start() override;


/**
* Prints the end of the \c neuron namespace
*/
void print_namespace_stop() override;
std::string namespace_name() override;


/****************************************************************************************/
Expand Down

0 comments on commit 41085b6

Please sign in to comment.