User Guide
visitor_utils.hpp File Reference

Utility functions for visitors implementation. More...

Detailed Description

Utility functions for visitors implementation.

Definition in file visitor_utils.hpp.

#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <ast/ast_decl.hpp>
#include <utils/common_utils.hpp>

Go to the source code of this file.

Namespaces

 nmodl
 encapsulates code generation backend implementations
 
 nmodl::visitor
 Implementation of different AST visitors.
 

Functions

std::string nmodl::visitor::suffix_random_string (const std::set< std::string > &vars, const std::string &original_string, const UseNumbersInString use_num=nmodl::utils::UseNumbersInString::WithNumbers)
 Return the "original_string" with a random suffix if "original_string" exists in "vars". More...
 
std::string nmodl::visitor::get_new_name (const std::string &name, const std::string &suffix, std::map< std::string, int > &variables)
 Return new name variable by appending _suffix_COUNT where COUNT is number of times the given variable is already used. More...
 
std::shared_ptr< ast::LocalListStatement > nmodl::visitor::get_local_list_statement (const ast::StatementBlock &node)
 Return pointer to local statement in the given block, otherwise nullptr. More...
 
void nmodl::visitor::add_local_statement (ast::StatementBlock &node)
 Add empty local statement to given block if already doesn't exist. More...
 
LocalVar * nmodl::visitor::add_local_variable (ast::StatementBlock &node, const std::string &varname)
 Add new local variable to the block. More...
 
LocalVar * nmodl::visitor::add_local_variable (StatementBlock &node, Identifier *varname)
 
LocalVar * nmodl::visitor::add_local_variable (StatementBlock &node, const std::string &varname, int dim)
 
std::shared_ptr< Statement > nmodl::visitor::create_statement (const std::string &code_statement)
 Convert given code statement (in string format) to corresponding ast node. More...
 
std::vector< std::shared_ptr< Statement > > nmodl::visitor::create_statements (const std::vector< std::string >::const_iterator &code_statements_beg, const std::vector< std::string >::const_iterator &code_statements_end)
 Same as for create_statement but for vectors of strings. More...
 
std::shared_ptr< StatementBlock > nmodl::visitor::create_statement_block (const std::vector< std::string > &code_statements)
 Convert given code statement (in string format) to corresponding ast node. More...
 
std::set< std::string > nmodl::visitor::get_global_vars (const ast::Program &node)
 Return set of strings with the names of all global variables. More...
 
bool nmodl::visitor::calls_function (const ast::Ast &node, const std::string &name)
 Checks whether block contains a call to a particular function. More...
 
std::vector< std::shared_ptr< const ast::Ast > > nmodl::collect_nodes (const ast::Ast &node, const std::vector< ast::AstNodeType > &types={})
 traverse node recursively and collect nodes of given types More...
 
std::vector< std::shared_ptr< ast::Ast > > nmodl::collect_nodes (ast::Ast &node, const std::vector< ast::AstNodeType > &types={})
 traverse node recursively and collect nodes of given types More...
 
bool nmodl::solver_exists (const ast::Ast &node, const std::string &name)
 Whether or not a solver of type name exists in the AST. More...
 
bool nmodl::node_exists (const ast::Ast &node, ast::AstNodeType ast_type)
 Whether a node of type ast_type exists as a subnode of node. More...
 
std::string nmodl::to_nmodl (const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types={})
 Given AST node, return the NMODL string representation. More...
 
template<typename T >
std::enable_if< std::is_base_of< ast::Ast, T >::value, std::string >::type nmodl::to_nmodl (const std::shared_ptr< T > &node, const std::set< ast::AstNodeType > &exclude_types={})
 Given a shared pointer to an AST node, return the NMODL string representation. More...
 
std::string nmodl::to_json (const ast::Ast &node, bool compact=false, bool expand=false, bool add_nmodl=false)
 Given AST node, return the JSON string representation. More...
 
std::string nmodl::statement_dependencies_key (const std::shared_ptr< ast::Expression > &lhs)
 The result.first of statement_dependencies. More...
 
std::pair< std::string, std::unordered_set< std::string > > nmodl::statement_dependencies (const std::shared_ptr< ast::Expression > &lhs, const std::shared_ptr< ast::Expression > &rhs)
 If lhs and rhs combined represent an assignment (we assume to have an "=" in between them) we extract the variables on which the assigned variable depends on. More...
 
std::string nmodl::get_indexed_name (const ast::IndexedName &node)
 Given a Indexed node, return the name with index. More...
 
std::string nmodl::get_full_var_name (const ast::VarName &node)
 Given a VarName node, return the full var name including index. More...
 
bool nmodl::is_random_construct_function (const std::string &name)
 Is given name a one of the function for RANDOM construct. More...
 
bool nmodl::is_nrn_pointing (const std::string &name)
 Is given name nrn_pointing. More...