User Guide
|
Implementation of different AST visitors. More...
Implementation of different AST visitors.
Namespaces | |
test | |
Classes | |
class | AfterCVodeToCnexpVisitor |
Visitor to change usage of after_cvode solver to cnexp. More... | |
class | AstVisitor |
Concrete visitor for all AST classes. More... | |
class | ConstantFolderVisitor |
Perform constant folding of integer/float/double expressions. More... | |
class | ConstAstVisitor |
Concrete constant visitor for all AST classes. More... | |
class | ConstVisitor |
Abstract base class for all constant visitors implementation. More... | |
class | CreateLongitudinalDiffusionBlocks |
class | CvodeHelperVisitor |
class | CvodeVisitor |
Visitor used for generating the necessary AST nodes for CVODE. More... | |
class | DefUseAnalyzeVisitor |
Visitor to return Def-Use chain for a given variable in the block/node More... | |
class | DUChain |
Def-Use chain for an AST node. More... | |
class | DUInstance |
Represent use of a variable in the statement. More... | |
class | FunctionCallpathVisitor |
Visitor for traversing FunctionBlock s and ProcedureBlocks through their FunctionCall s More... | |
class | GlobalToRangeVisitor |
Visitor to convert GLOBAL variables to RANGE variables. More... | |
class | ImplicitArgumentVisitor |
Visitor for adding implicit arguments to [Core]NEURON functions. More... | |
class | IndexedNameVisitor |
Get node name with indexed for the IndexedName node and the dependencies of DiffEqExpression node. More... | |
class | IndexRemover |
Helper visitor to replace index of array variable with integer. More... | |
class | InlineVisitor |
Visitor to inline local procedure and function calls More... | |
class | JSONVisitor |
Visitor for printing AST in JSON format More... | |
class | KineticBlockVisitor |
Visitor for kinetic block statements More... | |
class | LocalizeKineticRatesVisitor |
class | LocalizeVisitor |
Visitor to transform global variable usage to local More... | |
class | LocalRateNames |
class | LocalToAssignedVisitor |
Visitor to convert top level LOCAL variables to ASSIGNED variables. More... | |
class | LocalVarRenameVisitor |
Visitor to rename local variables conflicting with global scope More... | |
class | LoopUnrollVisitor |
Unroll for loop in the AST. More... | |
class | MetaAstLookupVisitor |
class | NeuronSolveVisitor |
Visitor that solves ODEs using old solvers of NEURON More... | |
class | NmodlPrintVisitor |
Visitor for printing AST back to NMODL More... | |
class | NonStiffVisitor |
class | PerfVisitor |
Visitor for measuring performance related information More... | |
class | RenameFunctionArgumentsVisitor |
class | RenameVisitor |
Blindly rename given variable to new name More... | |
class | SemanticAnalysisVisitor |
Visitor to check some semantic rules on the AST More... | |
class | SolveBlockVisitor |
Replace solve block statements with actual solution node in the AST. More... | |
class | SteadystateVisitor |
Visitor for STEADYSTATE solve statements More... | |
class | StiffVisitor |
class | SympyConductanceVisitor |
Visitor for generating CONDUCTANCE statements for ions More... | |
class | SympyReplaceSolutionsVisitor |
Replace statements in node with pre_solve_statements, tmp_statements, and solutions. More... | |
class | SympySolverVisitor |
Visitor for systems of algebraic and differential equations More... | |
class | SymtabVisitor |
Concrete visitor for constructing symbol table from AST. More... | |
class | UnitsVisitor |
Visitor for Units blocks of AST. More... | |
class | VarUsageVisitor |
Check if variable is used in given block. More... | |
class | VerbatimVarRenameVisitor |
Rename variable in verbatim block. More... | |
class | VerbatimVisitor |
Visitor for verbatim blocks of AST More... | |
class | Visitor |
Abstract base class for all visitors implementation. More... | |
Typedefs | |
using | AstLookupVisitor = MetaAstLookupVisitor< Visitor > |
using | ConstAstLookupVisitor = MetaAstLookupVisitor< ConstVisitor > |
Enumerations | |
enum | DUState { DUState::U, DUState::D, DUState::CD, DUState::LU, DUState::LD, DUState::UNKNOWN, DUState::CONDITIONAL_BLOCK, DUState::IF, DUState::ELSEIF, DUState::ELSE, DUState::NONE } |
Represent a state in Def-Use chain. More... | |
enum | DUVariableType { DUVariableType::Local, DUVariableType::Global } |
Variable type processed by DefUseAnalyzeVisitor. More... | |
Functions | |
static bool | is_number (const std::shared_ptr< ast::Expression > &node) |
check if given expression is a number note that the DEFINE node is already expanded to integer More... | |
static double | get_value (const std::shared_ptr< ast::Expression > &node) |
get value of a number node TODO : eval method can be added to virtual base class More... | |
static bool | supported_operator (ast::BinaryOp op) |
operators that currently implemented More... | |
static double | compute (double lhs, ast::BinaryOp op, double rhs) |
Evaluate binary operation TODO : add support for other binary operators like ^ (pow) More... | |
static int | get_index (const ast::IndexedName &node) |
static void | remove_conserve_statements (ast::StatementBlock &node) |
static void | remove_units (ast::BinaryExpression &node) |
static std::pair< std::string, std::optional< int > > | parse_independent_var (std::shared_ptr< ast::Identifier > node) |
static std::unordered_set< std::string > | get_indexed_variables (const ast::Expression &node, const std::string &ignored_name) |
set of all indexed variables not equal to ignored_name More... | |
static std::string | cvode_set_lhs (ast::BinaryExpression &node) |
static std::shared_ptr< ast::DerivativeBlock > | get_derivative_block (ast::Program &node) |
std::string | to_string (DUState state) |
DUState to string conversion for pretty-printing. More... | |
std::ostream & | operator<< (std::ostream &os, DUState state) |
std::shared_ptr< ast::Expression > | create_expr (const std::string &str_expr) |
static std::shared_ptr< ast::StatementBlock > | make_statement_block (ast::KineticBlock &kinetic_block, nmodl::ast::AstNodeType node_type) |
static std::shared_ptr< ast::LongitudinalDiffusionBlock > | create_block (ast::KineticBlock &node) |
static std::shared_ptr< ast::Expression > | unwrap (const std::shared_ptr< ast::Expression > &expr) |
return underlying expression wrapped by WrappedExpression More... | |
static std::shared_ptr< ast::ExpressionStatement > | unroll_for_loop (const std::shared_ptr< ast::FromStatement > &node) |
Unroll given for loop. More... | |
static bool | has_sympy_solution (const ast::Ast &node) |
check if given node contains sympy solution More... | |
static bool | conductance_statement_possible (const ast::BreakpointBlock &node) |
Analyse breakpoint block to check if it is safe to insert CONDUCTANCE statements. More... | |
static bool | is_local_statement (const std::shared_ptr< ast::Statement > &statement) |
Check if provided statement is local variable declaration statement. More... | |
static std::shared_ptr< Symbol > | create_symbol_for_node (ast::Node *node, NmodlType property, bool under_state_block) |
static void | add_external_symbols (symtab::ModelSymbolTable *symtab) |
std::string | 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 | 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 > | get_local_list_statement (const ast::StatementBlock &node) |
Return pointer to local statement in the given block, otherwise nullptr. More... | |
void | add_local_statement (ast::StatementBlock &node) |
Add empty local statement to given block if already doesn't exist. More... | |
LocalVar * | add_local_variable (StatementBlock &node, Identifier *varname) |
LocalVar * | add_local_variable (ast::StatementBlock &node, const std::string &varname) |
Add new local variable to the block. More... | |
LocalVar * | add_local_variable (StatementBlock &node, const std::string &varname, int dim) |
std::shared_ptr< Statement > | 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 > > | 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 > | 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 > | get_global_vars (const ast::Program &node) |
Return set of strings with the names of all global variables. More... | |
bool | calls_function (const ast::Ast &node, const std::string &name) |
Checks whether block contains a call to a particular function. More... | |
|
strong |
Represent a state in Def-Use chain.
Definition at line 28 of file defuse_analyze_visitor.hpp.
|
strong |
Variable type processed by DefUseAnalyzeVisitor.
DUVariableType::Local means that we are looking for LD, LU and CD DUStates, while Global means we are looking for U, D and CD DUStates.
Enumerator | |
---|---|
Local | |
Global |
Definition at line 59 of file defuse_analyze_visitor.hpp.
|
static |
Definition at line 168 of file symtab_visitor_helper.hpp.
void nmodl::visitor::add_local_statement | ( | StatementBlock & | node | ) |
Add empty local statement to given block if already doesn't exist.
Definition at line 84 of file visitor_utils.cpp.
ast::LocalVar * nmodl::visitor::add_local_variable | ( | StatementBlock & | node, |
const std::string & | varname | ||
) |
Add new local variable to the block.
Definition at line 107 of file visitor_utils.cpp.
ast::LocalVar * nmodl::visitor::add_local_variable | ( | StatementBlock & | node, |
const std::string & | varname, | ||
int | dim | ||
) |
Definition at line 112 of file visitor_utils.cpp.
ast::LocalVar * nmodl::visitor::add_local_variable | ( | StatementBlock & | node, |
Identifier * | varname | ||
) |
each block should already have local statement
Definition at line 93 of file visitor_utils.cpp.
bool nmodl::visitor::calls_function | ( | const ast::Ast & | node, |
const std::string & | name | ||
) |
Checks whether block contains a call to a particular function.
Definition at line 194 of file visitor_utils.cpp.
|
static |
Evaluate binary operation TODO : add support for other binary operators like ^ (pow)
Definition at line 45 of file constant_folder_visitor.cpp.
|
static |
Analyse breakpoint block to check if it is safe to insert CONDUCTANCE statements.
Most of the mod files have simple breakpoint blocks without any control flow statements. SympyConductanceVisitor just collects all the statements in the breakpoint block and insert conductance statements. If there are control flow statements like IF { a } ELSE { b }
block with conflicting current statements inside IF and ELSE blocks or VERBATIM block then the resulting CONDUCTANCE statements may be incorrect. For now the simple approach is to not generate CONDUCTANCE statements if if-else statements exist in the block.
node | Ast node for breakpoint block |
Definition at line 41 of file sympy_conductance_visitor.cpp.
|
static |
Definition at line 34 of file longitudinal_diffusion_visitor.cpp.
std::shared_ptr<ast::Expression> nmodl::visitor::create_expr | ( | const std::string & | str_expr | ) |
Definition at line 101 of file kinetic_block_visitor.cpp.
std::shared_ptr< ast::Statement > nmodl::visitor::create_statement | ( | const std::string & | code_statement | ) |
Convert given code statement (in string format) to corresponding ast node.
Create ast statement node from given code in string format.
We create dummy nmodl procedure containing given code statement and then parse it using NMODL parser. As there will be only one block with single statement, we return first statement.
Definition at line 127 of file visitor_utils.cpp.
std::shared_ptr< ast::StatementBlock > nmodl::visitor::create_statement_block | ( | const std::vector< std::string > & | code_statements | ) |
Convert given code statement (in string format) to corresponding ast node.
Create ast statement block node from given code in string format.
We create dummy nmodl procedure containing given code statement and then parse it using NMODL parser. As there will be only one block with single statement, we return first statement.
Definition at line 156 of file visitor_utils.cpp.
std::vector< std::shared_ptr< ast::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.
Definition at line 137 of file visitor_utils.cpp.
|
static |
add new symbol
extra property for state variables
Definition at line 25 of file symtab_visitor_helper.hpp.
|
static |
Definition at line 91 of file cvode_visitor.cpp.
|
static |
Definition at line 199 of file cvode_visitor.cpp.
std::set< std::string > nmodl::visitor::get_global_vars | ( | const Program & | node | ) |
Return set of strings with the names of all global variables.
Definition at line 171 of file visitor_utils.cpp.
|
static |
Definition at line 24 of file cvode_visitor.cpp.
|
static |
set of all indexed variables not equal to ignored_name
Definition at line 69 of file cvode_visitor.cpp.
std::shared_ptr< ast::LocalListStatement > nmodl::visitor::get_local_list_statement | ( | const StatementBlock & | node | ) |
Return pointer to local statement in the given block, otherwise nullptr.
Definition at line 74 of file visitor_utils.cpp.
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.
Definition at line 62 of file visitor_utils.cpp.
|
static |
get value of a number node TODO : eval method can be added to virtual base class
Definition at line 26 of file constant_folder_visitor.cpp.
|
static |
check if given node contains sympy solution
Definition at line 28 of file solve_block_visitor.cpp.
|
static |
Check if provided statement is local variable declaration statement.
statement | AST node representing statement in the MOD file |
Statement declaration could be wrapped into another statement type like expression statement and hence we try to look inside if it's really a variable declaration.
Definition at line 139 of file sympy_solver_visitor.cpp.
|
inlinestatic |
check if given expression is a number note that the DEFINE node is already expanded to integer
Definition at line 20 of file constant_folder_visitor.cpp.
|
static |
Definition at line 19 of file longitudinal_diffusion_visitor.cpp.
std::ostream & nmodl::visitor::operator<< | ( | std::ostream & | os, |
DUState | state | ||
) |
Definition at line 52 of file defuse_analyze_visitor.cpp.
|
static |
Definition at line 58 of file cvode_visitor.cpp.
|
static |
Definition at line 28 of file cvode_visitor.cpp.
|
static |
Definition at line 40 of file cvode_visitor.cpp.
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".
Return a std::string in the form "original_string"_"random_string", where random_string is a string defined in the nmodl::utils::SingletonRandomString for the original_string. Vars is a const ref to std::set<std::string> which holds the names that need to be checked for uniqueness. Choose if the "random_string" will include numbers using "use_num"
vars | a const ref to std::set<std::string> which holds the names of the variables we should check for uniqueness. Normally this is a vector of all the variables defined in the mod file. |
original_string | the original string to be suffixed with a random string |
use_num | a UseNumbersInString enum value to choose if the random string will include numbers |
Definition at line 33 of file visitor_utils.cpp.
|
inlinestatic |
operators that currently implemented
Definition at line 38 of file constant_folder_visitor.cpp.
std::string nmodl::visitor::to_string | ( | DUState | state | ) |
DUState to string conversion for pretty-printing.
Definition at line 23 of file defuse_analyze_visitor.cpp.
|
static |
Unroll given for loop.
node | From loop node in the AST |
loop can be in the form of FROM i=(0) TO (10)
so first unwrap all elements of the loop
we can unroll if iteration space of the loop is known after constant folding start, end and increment must be known
duplicate loop body and copy all statements to new vector
create new statement representing unrolled loop
Definition at line 37 of file loop_unroll_visitor.cpp.
|
static |
return underlying expression wrapped by WrappedExpression
Definition at line 22 of file loop_unroll_visitor.cpp.