Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit c8b626a

Browse files
committed
Replaced fmt literals with fmt::format
1 parent 5b74afb commit c8b626a

File tree

10 files changed

+103
-94
lines changed

10 files changed

+103
-94
lines changed

src/codegen/codegen_c_visitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ bool CodegenCVisitor::shadow_vector_setup_required() {
904904

905905
void CodegenCVisitor::print_channel_iteration_loop(const std::string& start = "start",
906906
const std::string& end = "end") {
907-
printer->start_block("for (int id = {}; id < {}; id++)"_format(start, end));
907+
printer->start_block(fmt::format("for (int id = {}; id < {}; id++)", start, end));
908908
}
909909

910910

src/codegen/codegen_c_visitor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ namespace nmodl {
3535
/// encapsulates code generation backend implementations
3636
namespace codegen {
3737

38-
using namespace fmt::literals;
3938
/**
4039
* @defgroup codegen Code Generation Implementation
4140
* @brief Implementations of code generation backends

src/codegen/codegen_driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ bool CodegenDriver::prepare_mod(std::shared_ptr<ast::Program> node, const std::s
157157
ast_to_nmodl(*node, filename);
158158
if (cfg.nmodl_ast && kineticBlockVisitor.get_conserve_statement_count()) {
159159
logger->warn(
160-
fmt::format("{} presents non-standard CONSERVE statements in DERIVATIVE blocks. Use it only for debugging/developing",
161-
filename));
160+
fmt::format("{} presents non-standard CONSERVE statements in DERIVATIVE blocks. "
161+
"Use it only for debugging/developing",
162+
filename));
162163
}
163164
}
164165

src/codegen/codegen_info.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace nmodl {
1717
namespace codegen {
1818

19-
using namespace fmt::literals;
2019
using symtab::syminfo::NmodlType;
2120
using visitor::VarUsageVisitor;
2221

@@ -328,7 +327,7 @@ void CodegenInfo::get_int_variables() {
328327
*/
329328
if (!watch_statements.empty()) {
330329
for (int i = 0; i < watch_statements.size() + 1; i++) {
331-
codegen_int_variables.emplace_back(make_symbol("watch{}"_format(i)),
330+
codegen_int_variables.emplace_back(make_symbol(fmt::format("watch{}", i)),
332331
false,
333332
false,
334333
true);

src/codegen/llvm/codegen_llvm_helper_visitor.cpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
namespace nmodl {
1919
namespace codegen {
2020

21-
using namespace fmt::literals;
22-
2321
using symtab::syminfo::Status;
2422

2523
/// initialize static member variables
@@ -148,7 +146,7 @@ void CodegenLLVMHelperVisitor::create_function_for_node(ast::Block& node) {
148146
auto name = new ast::Name(new ast::String(function_name));
149147

150148
/// return variable name has "ret_" prefix
151-
std::string return_var_name = "ret_{}"_format(function_name);
149+
std::string return_var_name = fmt::format("ret_{}", function_name);
152150
auto return_var = new ast::Name(new ast::String(return_var_name));
153151

154152
/// return type based on node type
@@ -337,11 +335,12 @@ void CodegenLLVMHelperVisitor::ion_read_statements(BlockType type,
337335
// ion variable to be read
338336
std::string& ion_varname = variable_names.second;
339337
// index for reading ion variable
340-
std::string index_varname = "{}_id"_format(varname);
338+
std::string index_varname = fmt::format("{}_id", varname);
341339
// first load the index
342-
std::string index_statement = "{} = {}_index[id]"_format(index_varname, ion_varname);
340+
std::string index_statement = fmt::format("{} = {}_index[id]", index_varname, ion_varname);
343341
// now assign the value
344-
std::string read_statement = "{} = {}[{}]"_format(varname, ion_varname, index_varname);
342+
std::string read_statement =
343+
fmt::format("{} = {}[{}]", varname, ion_varname, index_varname);
345344
// push index definition, index statement and actual read statement
346345
int_variables.push_back(index_varname);
347346
index_statements.push_back(visitor::create_statement(index_statement));
@@ -398,9 +397,9 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type,
398397
/// create write ion and corresponding index statements
399398
auto create_write_statements = [&](std::string ion_varname, std::string op, std::string rhs) {
400399
// index for writing ion variable
401-
std::string index_varname = "{}_id"_format(ion_varname);
400+
std::string index_varname = fmt::format("{}_id", ion_varname);
402401
// load index
403-
std::string index_statement = "{} = {}_index[id]"_format(index_varname, ion_varname);
402+
std::string index_statement = fmt::format("{} = {}_index[id]", index_varname, ion_varname);
404403
// push index definition, index statement and actual write statement
405404
int_variables.push_back(index_varname);
406405
index_statements.push_back(visitor::create_statement(index_statement));
@@ -425,7 +424,7 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type,
425424
// for synapse type
426425
if (info.point_process) {
427426
auto area = codegen::naming::NODE_AREA_VARIABLE;
428-
rhs += "*(1.e2/{0}[{0}_id])"_format(area);
427+
rhs += fmt::format("*(1.e2/{0}[{0}_id])", area);
429428
}
430429
create_write_statements(lhs, op, rhs);
431430
}
@@ -449,10 +448,10 @@ void CodegenLLVMHelperVisitor::ion_write_statements(BlockType type,
449448
index = 2;
450449
} else {
451450
/// \todo Unhandled case also in neuron implementation
452-
throw std::logic_error("codegen error for {} ion"_format(ion.name));
451+
throw std::logic_error(fmt::format("codegen error for {} ion", ion.name));
453452
}
454-
std::string ion_type_name = "{}_type"_format(ion.name);
455-
std::string lhs = "int {}"_format(ion_type_name);
453+
std::string ion_type_name = fmt::format("{}_type", ion.name);
454+
std::string lhs = fmt::format("int {}", ion_type_name);
456455
std::string op = "=";
457456
std::string rhs = ion_type_name;
458457
create_write_statements(lhs, op, rhs);
@@ -557,7 +556,7 @@ void CodegenLLVMHelperVisitor::rename_local_variables(ast::StatementBlock& node)
557556
/// rename local variable in entire statement block
558557
for (auto& var: local_statement->get_variables()) {
559558
std::string old_name = var->get_node_name();
560-
std::string new_name = "{}_{}"_format(old_name, local_block_counter);
559+
std::string new_name = fmt::format("{}_{}", old_name, local_block_counter);
561560
visitor::RenameVisitor(old_name, new_name).visit_statement_block(node);
562561
}
563562
}
@@ -668,9 +667,10 @@ void CodegenLLVMHelperVisitor::visit_nrn_state_block(ast::NrnStateBlock& node) {
668667
// prepare main body of the compute function
669668
{
670669
/// access node index and corresponding voltage
671-
index_statements.push_back(
672-
visitor::create_statement("node_id = node_index[{}]"_format(naming::INDUCTION_VAR)));
673-
body_statements.push_back(visitor::create_statement("v = {}[node_id]"_format(VOLTAGE_VAR)));
670+
index_statements.push_back(visitor::create_statement(
671+
fmt::format("node_id = node_index[{}]", naming::INDUCTION_VAR)));
672+
body_statements.push_back(
673+
visitor::create_statement(fmt::format("v = {}[node_id]", VOLTAGE_VAR)));
674674

675675
/// read ion variables
676676
ion_read_statements(
@@ -870,11 +870,11 @@ void CodegenLLVMHelperVisitor::print_nrn_current_body(const ast::BreakpointBlock
870870
// sum now all currents
871871
for (auto& current: info.currents) {
872872
statements.emplace_back(
873-
visitor::create_statement("current = current + {}"_format(current)));
873+
visitor::create_statement(fmt::format("current = current + {}", current)));
874874
}
875875

876876
// assign computed current to the given variable
877-
statements.emplace_back(visitor::create_statement("{} = current"_format(variable)));
877+
statements.emplace_back(visitor::create_statement(fmt::format("{} = current", variable)));
878878

879879
// create StatementBlock for better readability of the generated code and add that to the main
880880
// body statements
@@ -913,10 +913,10 @@ void CodegenLLVMHelperVisitor::print_nrn_cur_non_conductance_kernel(
913913
for (const auto& var: ion.writes) {
914914
if (ion.is_ionic_current(var)) {
915915
// also create local variable
916-
std::string name{"di{}"_format(ion.name)};
916+
std::string name{fmt::format("di{}", ion.name)};
917917
double_variables.emplace_back(name);
918918
body_statements.emplace_back(
919-
visitor::create_statement("{} = {}"_format(name, var)));
919+
visitor::create_statement(fmt::format("{} = {}", name, var)));
920920
}
921921
}
922922
}
@@ -931,32 +931,32 @@ void CodegenLLVMHelperVisitor::print_nrn_cur_non_conductance_kernel(
931931
// in case of point process we need to load area from another vector.
932932
if (info.point_process) {
933933
// create integer variable for index and then load value from area_index vector
934-
int_variables.emplace_back("{}_id"_format(naming::NODE_AREA_VARIABLE));
934+
int_variables.emplace_back(fmt::format("{}_id", naming::NODE_AREA_VARIABLE));
935935
index_statements.emplace_back(visitor::create_statement(
936-
" {0}_id = {0}_index[id]"_format(naming::NODE_AREA_VARIABLE)));
936+
fmt::format(" {0}_id = {0}_index[id]", naming::NODE_AREA_VARIABLE)));
937937
}
938938

939939
// update all ionic currents now
940940
for (const auto& ion: info.ions) {
941941
for (const auto& var: ion.writes) {
942942
if (ion.is_ionic_current(var)) {
943943
// variable on the lhs
944-
std::string lhs{"{}di{}dv"_format(naming::ION_VARNAME_PREFIX, ion.name)};
944+
std::string lhs{fmt::format("{}di{}dv", naming::ION_VARNAME_PREFIX, ion.name)};
945945

946946
// expression on the rhs
947-
std::string rhs{"(di{}-{})/0.001"_format(ion.name, var)};
947+
std::string rhs{fmt::format("(di{}-{})/0.001", ion.name, var)};
948948
if (info.point_process) {
949-
rhs += "*1.e2/{0}[{0}_id]"_format(naming::NODE_AREA_VARIABLE);
949+
rhs += fmt::format("*1.e2/{0}[{0}_id]", naming::NODE_AREA_VARIABLE);
950950
}
951951

952952
// load the index for lhs variable
953953
int_variables.emplace_back(lhs + "_id");
954-
std::string index_statement{"{}_id = {}_index[id]"_format(lhs, lhs)};
954+
std::string index_statement{fmt::format("{}_id = {}_index[id]", lhs, lhs)};
955955
index_statements.emplace_back(visitor::create_statement(index_statement));
956956

957957
// add statement that actually updates the
958-
body_statements.emplace_back(
959-
visitor::create_statement("{0}[{0}_id] = {0}[{0}_id] + {1}"_format(lhs, rhs)));
958+
body_statements.emplace_back(visitor::create_statement(
959+
fmt::format("{0}[{0}_id] = {0}[{0}_id] + {1}", lhs, rhs)));
960960
}
961961
}
962962
}
@@ -989,9 +989,10 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node
989989
/// prepare all function statements
990990
{
991991
/// access node index and corresponding voltage
992-
index_statements.push_back(
993-
visitor::create_statement("node_id = node_index[{}]"_format(naming::INDUCTION_VAR)));
994-
body_statements.push_back(visitor::create_statement("v = {}[node_id]"_format(VOLTAGE_VAR)));
992+
index_statements.push_back(visitor::create_statement(
993+
fmt::format("node_id = node_index[{}]", naming::INDUCTION_VAR)));
994+
body_statements.push_back(
995+
visitor::create_statement(fmt::format("v = {}[node_id]", VOLTAGE_VAR)));
995996

996997
/// read ion variables
997998
ion_read_statements(BlockType::Equation,
@@ -1020,7 +1021,7 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node
10201021
if (info.point_process) {
10211022
double_variables.emplace_back("mfactor");
10221023
body_statements.emplace_back(visitor::create_statement(
1023-
"mfactor = 1.e2/{0}[{0}_id]"_format(naming::NODE_AREA_VARIABLE)));
1024+
fmt::format("mfactor = 1.e2/{0}[{0}_id]", naming::NODE_AREA_VARIABLE)));
10241025
body_statements.emplace_back(visitor::create_statement("g = g*mfactor"));
10251026
body_statements.emplace_back(visitor::create_statement("rhs = rhs*mfactor"));
10261027
}
@@ -1046,9 +1047,9 @@ void CodegenLLVMHelperVisitor::visit_breakpoint_block(ast::BreakpointBlock& node
10461047
stringutils::remove_character(d_op, '=');
10471048

10481049
body_statements.emplace_back(visitor::create_statement(
1049-
"vec_rhs[node_id] = vec_rhs[node_id] {} rhs"_format(rhs_op)));
1050-
body_statements.emplace_back(
1051-
visitor::create_statement("vec_d[node_id] = vec_d[node_id] {} g"_format(d_op)));
1050+
fmt::format("vec_rhs[node_id] = vec_rhs[node_id] {} rhs", rhs_op)));
1051+
body_statements.emplace_back(visitor::create_statement(
1052+
fmt::format("vec_d[node_id] = vec_d[node_id] {} g", d_op)));
10521053
}
10531054
}
10541055

src/codegen/llvm/codegen_llvm_helper_visitor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace nmodl {
2525
namespace codegen {
2626

27-
using namespace fmt::literals;
2827
typedef std::vector<std::shared_ptr<ast::CodegenFunction>> CodegenFunctionVector;
2928

3029
/**
@@ -66,7 +65,7 @@ struct InstanceVarHelper {
6665
const auto& vars = instance->get_codegen_vars();
6766
auto it = find_variable(vars, name);
6867
if (it == vars.end()) {
69-
throw std::runtime_error("Can not find variable with name {}"_format(name));
68+
throw std::runtime_error(fmt::format("Can not find variable with name {}", name));
7069
}
7170
return *it;
7271
}
@@ -76,7 +75,8 @@ struct InstanceVarHelper {
7675
const auto& vars = instance->get_codegen_vars();
7776
auto it = find_variable(vars, name);
7877
if (it == vars.end()) {
79-
throw std::runtime_error("Can not find codegen variable with name {}"_format(name));
78+
throw std::runtime_error(
79+
fmt::format("Can not find codegen variable with name {}", name));
8080
}
8181
return (it - vars.begin());
8282
}

0 commit comments

Comments
 (0)