12 #include "utils/logger.hpp"
49 const auto&
name =
node.get_node_name();
51 !
node.get_parent()->is_function_call()) {
53 node.get_value()->set(new_name);
54 std::string token_string =
node.get_token() !=
nullptr
55 ?
" at " +
node.get_token()->position()
57 logger->debug(
"RenameVisitor :: Renaming variable {}{} to {}",
70 node.visit_children(*
this);
81 const auto& statement =
node.get_statement();
82 const auto&
text = statement->eval();
86 auto tokens =
driver.all_tokens();
89 for (
auto& token: tokens) {
95 logger->debug(
"RenameVisitor :: Renaming variable {} in VERBATIM block to {}",
102 statement->set(
result.str());
Auto generated AST classes declaration.
Represents a prime variable (for ODE)
Represents a C code block.
Class that binds all pieces together for parsing C verbatim blocks.
std::string new_var_name
new name
void visit_verbatim(const ast::Verbatim &node) override
Parse verbatim blocks and rename variable if it is used.
bool rename_verbatim
rename verbatim blocks as well
void visit_prime_name(const ast::PrimeName &node) override
Prime name has member order which is an integer.
void visit_name(const ast::Name &node) override
rename matching variable
bool add_prefix
add prefix to variable name
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 rename...
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...
bool add_random_suffix
add random suffix
std::regex var_name_regex
regex for searching which variables to replace
std::string new_var_name_prefix
variable prefix
std::shared_ptr< ast::Program > ast
ast::Ast* node
std::string suffix_random_string(const std::set< std::string > &vars, const std::string &original_string, const UseNumbersInString use_num)
Return the "original_string" with a random suffix if "original_string" exists in "vars".
std::set< std::string > get_global_vars(const Program &node)
Return set of strings with the names of all global variables.
encapsulates code generation backend implementations
static Node * node(Object *)
Blindly rename given variable to new name
nmodl::parser::UnitDriver driver
Utility functions for visitors implementation.