Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 30, 2024
1 parent 5768faa commit d8a9144
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,22 +647,25 @@ CodegenNeuronCppVisitor::function_table_parameters(const ast::FunctionTableBlock
}


std::unordered_map<std::string, std::string> get_nonglobal_local_variable_names(const symtab::SymbolTable& symtab) {
if(symtab.global_scope()) {
std::unordered_map<std::string, std::string> get_nonglobal_local_variable_names(
const symtab::SymbolTable& symtab) {
if (symtab.global_scope()) {
return {};
}

auto local_variables = symtab.get_variables(NmodlType::local_var);
auto parent_symtab = symtab.get_parent_table();
if(parent_symtab == nullptr) {
throw std::runtime_error("Internal NMODL error: non top-level symbol table doesn't have a parent.");
if (parent_symtab == nullptr) {
throw std::runtime_error(
"Internal NMODL error: non top-level symbol table doesn't have a parent.");
}

auto variable_names = get_nonglobal_local_variable_names(*parent_symtab);

for(const auto& symbol : local_variables) {
for (const auto& symbol: local_variables) {
auto status = symbol->get_status();
bool is_renamed = (status & symtab::syminfo::Status::renamed) != symtab::syminfo::Status::empty;
bool is_renamed = (status & symtab::syminfo::Status::renamed) !=
symtab::syminfo::Status::empty;
auto current_name = symbol->get_name();
auto mod_name = is_renamed ? symbol->get_original_name() : current_name;

Expand All @@ -673,7 +676,6 @@ std::unordered_map<std::string, std::string> get_nonglobal_local_variable_names(
}



std::vector<std::string> CodegenNeuronCppVisitor::print_verbatim_setup(
const ast::Verbatim& node,
const std::string& verbatim) {
Expand Down Expand Up @@ -707,12 +709,12 @@ std::vector<std::string> CodegenNeuronCppVisitor::print_verbatim_setup(
}
}

for (const auto& var : codegen_global_variables) {
for (const auto& var: codegen_global_variables) {
auto name = get_name(var);
print_macro(name, get_variable_name(name));
}

for (const auto& var : codegen_thread_variables) {
for (const auto& var: codegen_thread_variables) {
auto name = get_name(var);
print_macro(name, get_variable_name(name));
}
Expand Down
3 changes: 2 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
*
* Returns the names of all macros introduced.
*/
std::vector<std::string> print_verbatim_setup(const ast::Verbatim& node, const std::string& verbatim);
std::vector<std::string> print_verbatim_setup(const ast::Verbatim& node,
const std::string& verbatim);


/** Print `#undef`s to erase all compatibility macros.
Expand Down
1 change: 1 addition & 0 deletions test/usecases/verbatim/test_globals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from neuron import h, gui


def test_globals():
s = h.Section()
s.insert("globals")
Expand Down
1 change: 1 addition & 0 deletions test/usecases/verbatim/test_locals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from neuron import h, gui


def test_locals():
s = h.Section()
s.insert("locals")
Expand Down

0 comments on commit d8a9144

Please sign in to comment.