User Guide
nmodl::visitor::RenameVisitor Class Reference

Blindly rename given variable to new name More...

Detailed Description

Blindly rename given variable to new name

During inlining related passes we have to rename variables to avoid name conflicts. This pass "blindly" rename any given variable to new name. The error handling / legality checks are supposed to be done by other higher level passes. For example, local renaming pass should be done from inner-most block to top level block;

Todo:
Add log/warning messages.

Definition at line 43 of file rename_visitor.hpp.

#include <rename_visitor.hpp>

Inheritance diagram for nmodl::visitor::RenameVisitor:
nmodl::visitor::ConstAstVisitor nmodl::visitor::ConstVisitor

Public Member Functions

 RenameVisitor ()=default
 
 RenameVisitor (const std::string &old_name, std::string new_name)
 
 RenameVisitor (std::shared_ptr< ast::Program > ast, const std::string &old_name, std::string new_var_name_or_prefix, bool add_prefix, bool add_random_suffix)
 
std::string new_name_generator (const std::string &old_name)
 Check if variable is already renamed and use the same naming otherwise add the new_name to the renamed_variables map. More...
 
void set (const std::string &old_name, std::string new_name)
 
void enable_verbatim (bool state) noexcept
 
void visit_name (const ast::Name &node) override
 rename matching variable More...
 
void visit_prime_name (const ast::PrimeName &node) override
 Prime name has member order which is an integer. More...
 
void visit_verbatim (const ast::Verbatim &node) override
 Parse verbatim blocks and rename variable if it is used. More...
 
- Public Member Functions inherited from nmodl::visitor::ConstAstVisitor
void visit_node (const ast::Node &node) override
 visit node of type ast::Node More...
 
void visit_statement (const ast::Statement &node) override
 visit node of type ast::Statement More...
 
void visit_expression (const ast::Expression &node) override
 visit node of type ast::Expression More...
 
void visit_block (const ast::Block &node) override
 visit node of type ast::Block More...
 
void visit_identifier (const ast::Identifier &node) override
 visit node of type ast::Identifier More...
 
void visit_number (const ast::Number &node) override
 visit node of type ast::Number More...
 
void visit_string (const ast::String &node) override
 visit node of type ast::String More...
 
void visit_integer (const ast::Integer &node) override
 visit node of type ast::Integer More...
 
void visit_float (const ast::Float &node) override
 visit node of type ast::Float More...
 
void visit_double (const ast::Double &node) override
 visit node of type ast::Double More...
 
void visit_boolean (const ast::Boolean &node) override
 visit node of type ast::Boolean More...
 
void visit_name (const ast::Name &node) override
 visit node of type ast::Name More...
 
void visit_prime_name (const ast::PrimeName &node) override
 visit node of type ast::PrimeName More...
 
void visit_indexed_name (const ast::IndexedName &node) override
 visit node of type ast::IndexedName More...
 
void visit_var_name (const ast::VarName &node) override
 visit node of type ast::VarName More...
 
void visit_argument (const ast::Argument &node) override
 visit node of type ast::Argument More...
 
void visit_react_var_name (const ast::ReactVarName &node) override
 visit node of type ast::ReactVarName More...
 
void visit_read_ion_var (const ast::ReadIonVar &node) override
 visit node of type ast::ReadIonVar More...
 
void visit_write_ion_var (const ast::WriteIonVar &node) override
 visit node of type ast::WriteIonVar More...
 
void visit_nonspecific_cur_var (const ast::NonspecificCurVar &node) override
 visit node of type ast::NonspecificCurVar More...
 
void visit_electrode_cur_var (const ast::ElectrodeCurVar &node) override
 visit node of type ast::ElectrodeCurVar More...
 
void visit_range_var (const ast::RangeVar &node) override
 visit node of type ast::RangeVar More...
 
void visit_global_var (const ast::GlobalVar &node) override
 visit node of type ast::GlobalVar More...
 
void visit_pointer_var (const ast::PointerVar &node) override
 visit node of type ast::PointerVar More...
 
void visit_random_var (const ast::RandomVar &node) override
 visit node of type ast::RandomVar More...
 
void visit_bbcore_pointer_var (const ast::BbcorePointerVar &node) override
 visit node of type ast::BbcorePointerVar More...
 
void visit_extern_var (const ast::ExternVar &node) override
 visit node of type ast::ExternVar More...
 
void visit_param_block (const ast::ParamBlock &node) override
 visit node of type ast::ParamBlock More...
 
void visit_independent_block (const ast::IndependentBlock &node) override
 visit node of type ast::IndependentBlock More...
 
void visit_assigned_block (const ast::AssignedBlock &node) override
 visit node of type ast::AssignedBlock More...
 
void visit_state_block (const ast::StateBlock &node) override
 visit node of type ast::StateBlock More...
 
void visit_initial_block (const ast::InitialBlock &node) override
 visit node of type ast::InitialBlock More...
 
void visit_constructor_block (const ast::ConstructorBlock &node) override
 visit node of type ast::ConstructorBlock More...
 
void visit_destructor_block (const ast::DestructorBlock &node) override
 visit node of type ast::DestructorBlock More...
 
void visit_statement_block (const ast::StatementBlock &node) override
 visit node of type ast::StatementBlock More...
 
void visit_derivative_block (const ast::DerivativeBlock &node) override
 visit node of type ast::DerivativeBlock More...
 
void visit_linear_block (const ast::LinearBlock &node) override
 visit node of type ast::LinearBlock More...
 
void visit_non_linear_block (const ast::NonLinearBlock &node) override
 visit node of type ast::NonLinearBlock More...
 
void visit_discrete_block (const ast::DiscreteBlock &node) override
 visit node of type ast::DiscreteBlock More...
 
void visit_function_table_block (const ast::FunctionTableBlock &node) override
 visit node of type ast::FunctionTableBlock More...
 
void visit_function_block (const ast::FunctionBlock &node) override
 visit node of type ast::FunctionBlock More...
 
void visit_procedure_block (const ast::ProcedureBlock &node) override
 visit node of type ast::ProcedureBlock More...
 
void visit_net_receive_block (const ast::NetReceiveBlock &node) override
 visit node of type ast::NetReceiveBlock More...
 
void visit_solve_block (const ast::SolveBlock &node) override
 visit node of type ast::SolveBlock More...
 
void visit_breakpoint_block (const ast::BreakpointBlock &node) override
 visit node of type ast::BreakpointBlock More...
 
void visit_before_block (const ast::BeforeBlock &node) override
 visit node of type ast::BeforeBlock More...
 
void visit_after_block (const ast::AfterBlock &node) override
 visit node of type ast::AfterBlock More...
 
void visit_ba_block (const ast::BABlock &node) override
 visit node of type ast::BABlock More...
 
void visit_for_netcon (const ast::ForNetcon &node) override
 visit node of type ast::ForNetcon More...
 
void visit_kinetic_block (const ast::KineticBlock &node) override
 visit node of type ast::KineticBlock More...
 
void visit_unit_block (const ast::UnitBlock &node) override
 visit node of type ast::UnitBlock More...
 
void visit_constant_block (const ast::ConstantBlock &node) override
 visit node of type ast::ConstantBlock More...
 
void visit_neuron_block (const ast::NeuronBlock &node) override
 visit node of type ast::NeuronBlock More...
 
void visit_unit (const ast::Unit &node) override
 visit node of type ast::Unit More...
 
void visit_double_unit (const ast::DoubleUnit &node) override
 visit node of type ast::DoubleUnit More...
 
void visit_local_var (const ast::LocalVar &node) override
 visit node of type ast::LocalVar More...
 
void visit_limits (const ast::Limits &node) override
 visit node of type ast::Limits More...
 
void visit_number_range (const ast::NumberRange &node) override
 visit node of type ast::NumberRange More...
 
void visit_constant_var (const ast::ConstantVar &node) override
 visit node of type ast::ConstantVar More...
 
void visit_binary_operator (const ast::BinaryOperator &node) override
 visit node of type ast::BinaryOperator More...
 
void visit_unary_operator (const ast::UnaryOperator &node) override
 visit node of type ast::UnaryOperator More...
 
void visit_reaction_operator (const ast::ReactionOperator &node) override
 visit node of type ast::ReactionOperator More...
 
void visit_paren_expression (const ast::ParenExpression &node) override
 visit node of type ast::ParenExpression More...
 
void visit_binary_expression (const ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
void visit_diff_eq_expression (const ast::DiffEqExpression &node) override
 visit node of type ast::DiffEqExpression More...
 
void visit_unary_expression (const ast::UnaryExpression &node) override
 visit node of type ast::UnaryExpression More...
 
void visit_non_lin_equation (const ast::NonLinEquation &node) override
 visit node of type ast::NonLinEquation More...
 
void visit_lin_equation (const ast::LinEquation &node) override
 visit node of type ast::LinEquation More...
 
void visit_function_call (const ast::FunctionCall &node) override
 visit node of type ast::FunctionCall More...
 
void visit_watch (const ast::Watch &node) override
 visit node of type ast::Watch More...
 
void visit_ba_block_type (const ast::BABlockType &node) override
 visit node of type ast::BABlockType More...
 
void visit_unit_def (const ast::UnitDef &node) override
 visit node of type ast::UnitDef More...
 
void visit_factor_def (const ast::FactorDef &node) override
 visit node of type ast::FactorDef More...
 
void visit_valence (const ast::Valence &node) override
 visit node of type ast::Valence More...
 
void visit_unit_state (const ast::UnitState &node) override
 visit node of type ast::UnitState More...
 
void visit_local_list_statement (const ast::LocalListStatement &node) override
 visit node of type ast::LocalListStatement More...
 
void visit_model (const ast::Model &node) override
 visit node of type ast::Model More...
 
void visit_define (const ast::Define &node) override
 visit node of type ast::Define More...
 
void visit_include (const ast::Include &node) override
 visit node of type ast::Include More...
 
void visit_param_assign (const ast::ParamAssign &node) override
 visit node of type ast::ParamAssign More...
 
void visit_assigned_definition (const ast::AssignedDefinition &node) override
 visit node of type ast::AssignedDefinition More...
 
void visit_conductance_hint (const ast::ConductanceHint &node) override
 visit node of type ast::ConductanceHint More...
 
void visit_expression_statement (const ast::ExpressionStatement &node) override
 visit node of type ast::ExpressionStatement More...
 
void visit_protect_statement (const ast::ProtectStatement &node) override
 visit node of type ast::ProtectStatement More...
 
void visit_from_statement (const ast::FromStatement &node) override
 visit node of type ast::FromStatement More...
 
void visit_while_statement (const ast::WhileStatement &node) override
 visit node of type ast::WhileStatement More...
 
void visit_if_statement (const ast::IfStatement &node) override
 visit node of type ast::IfStatement More...
 
void visit_else_if_statement (const ast::ElseIfStatement &node) override
 visit node of type ast::ElseIfStatement More...
 
void visit_else_statement (const ast::ElseStatement &node) override
 visit node of type ast::ElseStatement More...
 
void visit_watch_statement (const ast::WatchStatement &node) override
 visit node of type ast::WatchStatement More...
 
void visit_mutex_lock (const ast::MutexLock &node) override
 visit node of type ast::MutexLock More...
 
void visit_mutex_unlock (const ast::MutexUnlock &node) override
 visit node of type ast::MutexUnlock More...
 
void visit_conserve (const ast::Conserve &node) override
 visit node of type ast::Conserve More...
 
void visit_compartment (const ast::Compartment &node) override
 visit node of type ast::Compartment More...
 
void visit_lon_difuse (const ast::LonDifuse &node) override
 visit node of type ast::LonDifuse More...
 
void visit_reaction_statement (const ast::ReactionStatement &node) override
 visit node of type ast::ReactionStatement More...
 
void visit_lag_statement (const ast::LagStatement &node) override
 visit node of type ast::LagStatement More...
 
void visit_constant_statement (const ast::ConstantStatement &node) override
 visit node of type ast::ConstantStatement More...
 
void visit_table_statement (const ast::TableStatement &node) override
 visit node of type ast::TableStatement More...
 
void visit_suffix (const ast::Suffix &node) override
 visit node of type ast::Suffix More...
 
void visit_useion (const ast::Useion &node) override
 visit node of type ast::Useion More...
 
void visit_nonspecific (const ast::Nonspecific &node) override
 visit node of type ast::Nonspecific More...
 
void visit_electrode_current (const ast::ElectrodeCurrent &node) override
 visit node of type ast::ElectrodeCurrent More...
 
void visit_range (const ast::Range &node) override
 visit node of type ast::Range More...
 
void visit_global (const ast::Global &node) override
 visit node of type ast::Global More...
 
void visit_random_var_list (const ast::RandomVarList &node) override
 visit node of type ast::RandomVarList More...
 
void visit_pointer (const ast::Pointer &node) override
 visit node of type ast::Pointer More...
 
void visit_bbcore_pointer (const ast::BbcorePointer &node) override
 visit node of type ast::BbcorePointer More...
 
void visit_external (const ast::External &node) override
 visit node of type ast::External More...
 
void visit_thread_safe (const ast::ThreadSafe &node) override
 visit node of type ast::ThreadSafe More...
 
void visit_verbatim (const ast::Verbatim &node) override
 visit node of type ast::Verbatim More...
 
void visit_line_comment (const ast::LineComment &node) override
 visit node of type ast::LineComment More...
 
void visit_block_comment (const ast::BlockComment &node) override
 visit node of type ast::BlockComment More...
 
void visit_ontology_statement (const ast::OntologyStatement &node) override
 visit node of type ast::OntologyStatement More...
 
void visit_program (const ast::Program &node) override
 visit node of type ast::Program More...
 
void visit_nrn_state_block (const ast::NrnStateBlock &node) override
 visit node of type ast::NrnStateBlock More...
 
void visit_eigen_newton_solver_block (const ast::EigenNewtonSolverBlock &node) override
 visit node of type ast::EigenNewtonSolverBlock More...
 
void visit_eigen_linear_solver_block (const ast::EigenLinearSolverBlock &node) override
 visit node of type ast::EigenLinearSolverBlock More...
 
void visit_wrapped_expression (const ast::WrappedExpression &node) override
 visit node of type ast::WrappedExpression More...
 
void visit_derivimplicit_callback (const ast::DerivimplicitCallback &node) override
 visit node of type ast::DerivimplicitCallback More...
 
void visit_solution_expression (const ast::SolutionExpression &node) override
 visit node of type ast::SolutionExpression More...
 
void visit_update_dt (const ast::UpdateDt &node) override
 visit node of type ast::UpdateDt More...
 
- Public Member Functions inherited from nmodl::visitor::ConstVisitor
virtual ~ConstVisitor ()=default
 

Private Attributes

std::shared_ptr< ast::Programast
 ast::Ast* node More...
 
std::regex var_name_regex
 regex for searching which variables to replace More...
 
std::string new_var_name
 new name More...
 
std::string new_var_name_prefix
 variable prefix More...
 
std::unordered_map< std::string, std::string > renamed_variables
 Map that keeps the renamed variables to keep the same random suffix when a variable is renamed across the whole file. More...
 
bool add_prefix = false
 add prefix to variable name More...
 
bool add_random_suffix = false
 add random suffix More...
 
bool rename_verbatim = true
 rename verbatim blocks as well More...
 

Constructor & Destructor Documentation

◆ RenameVisitor() [1/3]

nmodl::visitor::RenameVisitor::RenameVisitor ( )
default

◆ RenameVisitor() [2/3]

nmodl::visitor::RenameVisitor::RenameVisitor ( const std::string &  old_name,
std::string  new_name 
)
inline

Definition at line 73 of file rename_visitor.hpp.

◆ RenameVisitor() [3/3]

nmodl::visitor::RenameVisitor::RenameVisitor ( std::shared_ptr< ast::Program ast,
const std::string &  old_name,
std::string  new_var_name_or_prefix,
bool  add_prefix,
bool  add_random_suffix 
)
inline

Definition at line 77 of file rename_visitor.hpp.

Member Function Documentation

◆ enable_verbatim()

void nmodl::visitor::RenameVisitor::enable_verbatim ( bool  state)
inlinenoexcept

Definition at line 102 of file rename_visitor.hpp.

◆ new_name_generator()

std::string nmodl::visitor::RenameVisitor::new_name_generator ( const std::string &  old_name)

Check if variable is already renamed and use the same naming otherwise add the new_name to the renamed_variables map.

Definition at line 20 of file rename_visitor.cpp.

◆ set()

void nmodl::visitor::RenameVisitor::set ( const std::string &  old_name,
std::string  new_name 
)
inline

Definition at line 97 of file rename_visitor.hpp.

◆ visit_name()

void nmodl::visitor::RenameVisitor::visit_name ( const ast::Name node)
overridevirtual

rename matching variable

Implements nmodl::visitor::ConstVisitor.

Definition at line 48 of file rename_visitor.cpp.

◆ visit_prime_name()

void nmodl::visitor::RenameVisitor::visit_prime_name ( const ast::PrimeName node)
overridevirtual

Prime name has member order which is an integer.

In theory integer could be "macro name" and hence could end-up renaming macro. In practice this won't be an issue as we order is set by parser. To be safe we are only renaming prime variable.

Implements nmodl::visitor::ConstVisitor.

Definition at line 68 of file rename_visitor.cpp.

◆ visit_verbatim()

void nmodl::visitor::RenameVisitor::visit_verbatim ( const ast::Verbatim node)
overridevirtual

Parse verbatim blocks and rename variable if it is used.

Check if variable is already renamed and use the same naming otherwise add the new_name to the renamed_variables map

Implements nmodl::visitor::ConstVisitor.

Definition at line 75 of file rename_visitor.cpp.

Member Data Documentation

◆ add_prefix

bool nmodl::visitor::RenameVisitor::add_prefix = false
private

add prefix to variable name

Definition at line 62 of file rename_visitor.hpp.

◆ add_random_suffix

bool nmodl::visitor::RenameVisitor::add_random_suffix = false
private

add random suffix

Definition at line 65 of file rename_visitor.hpp.

◆ ast

std::shared_ptr<ast::Program> nmodl::visitor::RenameVisitor::ast
private

ast::Ast* node

Definition at line 46 of file rename_visitor.hpp.

◆ new_var_name

std::string nmodl::visitor::RenameVisitor::new_var_name
private

new name

Definition at line 52 of file rename_visitor.hpp.

◆ new_var_name_prefix

std::string nmodl::visitor::RenameVisitor::new_var_name_prefix
private

variable prefix

Definition at line 55 of file rename_visitor.hpp.

◆ rename_verbatim

bool nmodl::visitor::RenameVisitor::rename_verbatim = true
private

rename verbatim blocks as well

Definition at line 68 of file rename_visitor.hpp.

◆ renamed_variables

std::unordered_map<std::string, std::string> nmodl::visitor::RenameVisitor::renamed_variables
private

Map that keeps the renamed variables to keep the same random suffix when a variable is renamed across the whole file.

Definition at line 59 of file rename_visitor.hpp.

◆ var_name_regex

std::regex nmodl::visitor::RenameVisitor::var_name_regex
private

regex for searching which variables to replace

Definition at line 49 of file rename_visitor.hpp.


The documentation for this class was generated from the following files: