User Guide
nmodl::codegen::CodegenCppVisitor Class Referenceabstract

Visitor for printing C++ code compatible with legacy api of CoreNEURON More...

Detailed Description

Visitor for printing C++ code compatible with legacy api of CoreNEURON

Todo:
  • Handle define statement (i.e. macros)
  • If there is a return statement in the verbatim block of inlined function then it will be error. Need better error checking. For example, see netstim.mod where we have removed return from verbatim block.

Definition at line 180 of file codegen_cpp_visitor.hpp.

#include <codegen_cpp_visitor.hpp>

Inheritance diagram for nmodl::codegen::CodegenCppVisitor:
nmodl::visitor::ConstAstVisitor nmodl::visitor::ConstVisitor nmodl::codegen::CodegenCoreneuronCppVisitor nmodl::codegen::CodegenNeuronCppVisitor nmodl::codegen::CodegenAccVisitor

Public Member Functions

 CodegenCppVisitor (std::string mod_filename, const std::string &output_dir, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
 Constructs the C++ code generator visitor. More...
 
 CodegenCppVisitor (std::string mod_filename, std::ostream &stream, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
 Constructs the C++ code generator visitor. More...
 
void setup (const ast::Program &node)
 Setup the target backend code generator. More...
 
void visit_program (const ast::Program &program) override
 Main and only member function to call after creating an instance of this class. More...
 
virtual void print_mechanism_range_var_structure (bool print_initializers)=0
 Print the structure that wraps all range and int variables required for the NMODL. 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
 

Protected Types

using SymbolType = std::shared_ptr< symtab::Symbol >
 
using ParamVector = std::vector< std::tuple< std::string, std::string, std::string, std::string > >
 A vector of parameters represented by a 4-tuple of strings: More...
 

Protected Member Functions

std::string nmodl_version () const noexcept
 Return Nmodl language version. More...
 
virtual std::string simulator_name ()=0
 Name of the simulator the code was generated for. More...
 
std::string instance_struct () const
 Name of structure that wraps range variables. More...
 
std::string node_data_struct () const
 Name of structure that wraps node variables. More...
 
std::string global_struct () const
 Name of structure that wraps global variables. More...
 
std::string global_struct_instance () const
 Name of the (host-only) global instance of global_struct More...
 
virtual std::string backend_name () const =0
 Name of the code generation backend. More...
 
const char * local_var_type () const noexcept
 Data type for the local variables. More...
 
const char * default_float_data_type () const noexcept
 Default data type for floating point elements. More...
 
const std::string & float_data_type () const noexcept
 Data type for floating point elements specified on command line. More...
 
const char * default_int_data_type () const noexcept
 Default data type for integer (offset) elements. More...
 
const char * operator_for_rhs () const noexcept
 Operator for rhs vector update (matrix update) More...
 
const char * operator_for_d () const noexcept
 Operator for diagonal vector update (matrix update) More...
 
std::string get_channel_info_var_name () const noexcept
 Name of channel info variable. More...
 
bool ion_variable_struct_required () const
 Check if a structure for ion variables is required. More...
 
template<typename T >
bool has_parameter_of_name (const T &node, const std::string &name)
 Check if function or procedure node has parameter with given name. More...
 
bool net_send_buffer_required () const noexcept
 Check if net_send_buffer is required. More...
 
bool net_receive_buffering_required () const noexcept
 Check if net receive/send buffering kernels required. More...
 
bool nrn_state_required () const noexcept
 Check if nrn_state function is required. More...
 
bool nrn_cur_required () const noexcept
 Check if nrn_cur function is required. More...
 
bool net_receive_required () const noexcept
 Check if net_receive function is required. More...
 
bool range_variable_setup_required () const noexcept
 Check if setup_range_variable function is required. More...
 
bool net_receive_exist () const noexcept
 Check if net_receive node exist. More...
 
bool breakpoint_exist () const noexcept
 Check if breakpoint node exist. More...
 
bool defined_method (const std::string &name) const
 Check if given method is defined in this model. More...
 
bool is_net_send (const std::string &name) const noexcept
 Checks if given function name is net_send. More...
 
bool is_net_move (const std::string &name) const noexcept
 Checks if given function name is net_move. More...
 
bool is_net_event (const std::string &name) const noexcept
 Checks if given function name is net_event. More...
 
virtual int position_of_float_var (const std::string &name) const =0
 Determine the position in the data array for a given float variable. More...
 
virtual int position_of_int_var (const std::string &name) const =0
 Determine the position in the data array for a given int variable. More...
 
int float_variables_size () const
 Number of float variables in the model. More...
 
int int_variables_size () const
 Number of integer variables in the model. More...
 
std::string format_double_string (const std::string &value)
 Convert a given double value to its string representation. More...
 
std::string format_float_string (const std::string &value)
 Convert a given float value to its string representation. More...
 
void update_index_semantics ()
 populate all index semantics needed for registration with coreneuron More...
 
std::vector< SymbolTypeget_float_variables () const
 Determine all float variables required during code generation. More...
 
std::vector< IndexVariableInfoget_int_variables ()
 Determine all int variables required during code generation. More...
 
std::vector< std::string > ion_read_statements (BlockType type) const
 For a given output block type, return statements for all read ion variables. More...
 
std::vector< std::string > ion_read_statements_optimized (BlockType type) const
 For a given output block type, return minimal statements for all read ion variables. More...
 
std::vector< ShadowUseStatemention_write_statements (BlockType type)
 For a given output block type, return statements for writing back ion variables. More...
 
std::string process_shadow_update_statement (const ShadowUseStatement &statement, BlockType type)
 Process shadow update statement. More...
 
std::string breakpoint_current (std::string current) const
 Determine the variable name for the "current" used in breakpoint block taking into account intermediate code transformations. More...
 
virtual void print_atomic_reduction_pragma ()=0
 Print atomic update pragma for reduction statements. More...
 
virtual void print_global_var_struct_decl ()
 Instantiate global var instance. More...
 
virtual bool optimize_ion_variable_copies () const =0
 Check if ion variable copies should be avoided. More...
 
void print_statement_block (const ast::StatementBlock &node, bool open_brace=true, bool close_brace=true)
 Print any statement block in nmodl with option to (not) print braces. More...
 
virtual void print_function_call (const ast::FunctionCall &node)
 Print call to internal or external function. More...
 
virtual void print_net_send_call (const ast::FunctionCall &node)=0
 Print call to net_send. More...
 
virtual void print_net_move_call (const ast::FunctionCall &node)=0
 Print call to net_move. More...
 
virtual void print_net_event_call (const ast::FunctionCall &node)=0
 Print call to net_event. More...
 
virtual void print_function_prototypes ()=0
 Print function and procedures prototype declaration. More...
 
virtual void print_function_or_procedure (const ast::Block &node, const std::string &name)=0
 Print nmodl function or procedure (common code) More...
 
virtual void print_function_procedure_helper (const ast::Block &node)=0
 Common helper function to help printing function or procedure blocks. More...
 
virtual void print_procedure (const ast::ProcedureBlock &node)=0
 Print NMODL procedure in target backend code. More...
 
virtual void print_function (const ast::FunctionBlock &node)=0
 Print NMODL function in target backend code. More...
 
void rename_function_arguments ()
 Rename function/procedure arguments that conflict with default arguments. More...
 
template<typename T >
void print_vector_elements (const std::vector< T > &elements, const std::string &separator, const std::string &prefix="")
 Print the items in a vector as a list. More...
 
virtual std::string internal_method_arguments ()=0
 Arguments for functions that are defined and used internally. More...
 
virtual ParamVector internal_method_parameters ()=0
 Parameters for internally defined functions. More...
 
virtual const char * external_method_arguments () noexcept=0
 Arguments for external functions called from generated code. More...
 
virtual const char * external_method_parameters (bool table=false) noexcept=0
 Parameters for functions in generated code that are called back from external code. More...
 
virtual std::string nrn_thread_arguments () const =0
 Arguments for "_threadargs_" macro in neuron implementation. More...
 
virtual std::string nrn_thread_internal_arguments ()=0
 Arguments for "_threadargs_" macro in neuron implementation. More...
 
virtual std::string process_verbatim_text (std::string const &text)=0
 Process a verbatim block for possible variable renaming. More...
 
virtual std::string register_mechanism_arguments () const =0
 Arguments for register_mech or point_register_mech function. More...
 
std::string add_escape_quote (const std::string &text) const
 Add quotes to string to be output. More...
 
std::string method_name (const std::string &name) const
 Constructs the name of a function or procedure. More...
 
SymbolType make_symbol (const std::string &name) const
 Creates a temporary symbol. More...
 
virtual std::string conc_write_statement (const std::string &ion_name, const std::string &concentration, int index)=0
 Generate Function call statement for nrn_wrote_conc. More...
 
virtual void print_namespace_start ()=0
 Prints the start of the simulator namespace. More...
 
virtual void print_namespace_stop ()=0
 Prints the end of the simulator namespace. More...
 
std::string update_if_ion_variable_name (const std::string &name) const
 Determine the updated name if the ion variable has been optimized. More...
 
virtual std::string float_variable_name (const SymbolType &symbol, bool use_instance) const =0
 Determine the name of a float variable given its symbol. More...
 
virtual std::string int_variable_name (const IndexVariableInfo &symbol, const std::string &name, bool use_instance) const =0
 Determine the name of an int variable given its symbol. More...
 
virtual std::string global_variable_name (const SymbolType &symbol, bool use_instance=true) const =0
 Determine the variable name for a global variable given its symbol. More...
 
virtual std::string get_variable_name (const std::string &name, bool use_instance=true) const =0
 Determine variable name in the structure of mechanism properties. More...
 
virtual void print_backend_info ()=0
 Print top file header printed in generated code. More...
 
virtual void print_standard_includes ()=0
 Print standard C/C++ includes. More...
 
virtual void print_sdlists_init (bool print_initializers)=0
 
virtual void print_mechanism_global_var_structure (bool print_initializers)=0
 Print the structure that wraps all global variables used in the NMODL. More...
 
virtual void print_global_var_struct_assertions () const
 Print static assertions about the global variable struct. More...
 
void print_prcellstate_macros () const
 Print declaration of macro NRN_PRCELLSTATE for debugging. More...
 
void print_mechanism_info ()
 Print backend code for byte array that has mechanism information (to be registered with NEURON/CoreNEURON) More...
 
virtual void print_global_variables_for_hoc ()=0
 Print byte arrays that register scalar and vector variables for hoc interface. More...
 
virtual void print_mechanism_register ()=0
 Print the mechanism registration function. More...
 
virtual void print_global_function_common_code (BlockType type, const std::string &function_name="")=0
 Print common code for global functions like nrn_init, nrn_cur and nrn_state. More...
 
virtual void print_nrn_constructor ()=0
 Print nrn_constructor function definition. More...
 
virtual void print_nrn_destructor ()=0
 Print nrn_destructor function definition. More...
 
virtual void print_nrn_alloc ()=0
 Print nrn_alloc function definition. More...
 
virtual void print_nrn_state ()=0
 Print nrn_state / state update function definition. More...
 
virtual void print_nrn_current (const ast::BreakpointBlock &node)=0
 Print the nrn_current kernel. More...
 
virtual void print_nrn_cur_conductance_kernel (const ast::BreakpointBlock &node)=0
 Print the nrn_cur kernel with NMODL conductance keyword provisions. More...
 
virtual void print_nrn_cur_non_conductance_kernel ()=0
 Print the nrn_cur kernel without NMODL conductance keyword provisions. More...
 
virtual void print_nrn_cur_kernel (const ast::BreakpointBlock &node)=0
 Print main body of nrn_cur function. More...
 
virtual void print_fast_imem_calculation ()=0
 Print fast membrane current calculation code. More...
 
virtual void print_nrn_cur ()=0
 Print nrn_cur / current update function definition. More...
 
virtual void print_headers_include ()=0
 Print all includes. More...
 
virtual void print_namespace_begin ()=0
 Print start of namespaces. More...
 
virtual void print_namespace_end ()=0
 Print end of namespaces. More...
 
virtual void print_data_structures (bool print_initializers)=0
 Print all classes. More...
 
virtual void print_v_unused () const =0
 Set v_unused (voltage) for NRN_PRCELLSTATE feature. More...
 
virtual void print_g_unused () const =0
 Set g_unused (conductance) for NRN_PRCELLSTATE feature. More...
 
virtual void print_compute_functions ()=0
 Print all compute functions for every backend. More...
 
virtual void print_codegen_routines ()=0
 Print entry point to code generation. More...
 
void print_nmodl_constants ()
 Print the nmodl constants used in backend code. More...
 
void visit_binary_expression (const ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
void visit_binary_operator (const ast::BinaryOperator &node) override
 visit node of type ast::BinaryOperator More...
 
void visit_boolean (const ast::Boolean &node) override
 visit node of type ast::Boolean More...
 
void visit_double (const ast::Double &node) override
 visit node of type ast::Double 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_float (const ast::Float &node) override
 visit node of type ast::Float More...
 
void visit_from_statement (const ast::FromStatement &node) override
 visit node of type ast::FromStatement More...
 
void visit_function_call (const ast::FunctionCall &node) override
 visit node of type ast::FunctionCall More...
 
void visit_if_statement (const ast::IfStatement &node) override
 visit node of type ast::IfStatement More...
 
void visit_indexed_name (const ast::IndexedName &node) override
 visit node of type ast::IndexedName More...
 
void visit_integer (const ast::Integer &node) override
 visit node of type ast::Integer More...
 
void visit_local_list_statement (const ast::LocalListStatement &node) override
 visit node of type ast::LocalListStatement More...
 
void visit_name (const ast::Name &node) override
 visit node of type ast::Name More...
 
void visit_paren_expression (const ast::ParenExpression &node) override
 visit node of type ast::ParenExpression More...
 
void visit_prime_name (const ast::PrimeName &node) override
 visit node of type ast::PrimeName More...
 
void visit_statement_block (const ast::StatementBlock &node) override
 
void visit_string (const ast::String &node) override
 visit node of type ast::String More...
 
void visit_unary_operator (const ast::UnaryOperator &node) override
 visit node of type ast::UnaryOperator More...
 
void visit_unit (const ast::Unit &node) override
 visit node of type ast::Unit More...
 
void visit_var_name (const ast::VarName &node) override
 
void visit_verbatim (const ast::Verbatim &node) override
 visit node of type ast::Verbatim More...
 
void visit_while_statement (const ast::WhileStatement &node) override
 visit node of type ast::WhileStatement More...
 
void visit_update_dt (const ast::UpdateDt &node) override
 visit node of type ast::UpdateDt More...
 
void visit_protect_statement (const ast::ProtectStatement &node) override
 visit node of type ast::ProtectStatement 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_solution_expression (const ast::SolutionExpression &node) override
 visit node of type ast::SolutionExpression More...
 
std::string compute_method_name (BlockType type) const
 

Static Protected Member Functions

static bool need_semicolon (const ast::Statement &node)
 Check if a semicolon is required at the end of given statement. More...
 
static std::string get_parameter_str (const ParamVector &params)
 Generate the string representing the procedure parameter declaration. More...
 
static bool statement_to_skip (const ast::Statement &node)
 Check if given statement should be skipped during code generation. More...
 
static std::pair< std::string, std::string > read_ion_variable_name (const std::string &name)
 Return ion variable name and corresponding ion read variable name. More...
 
static std::pair< std::string, std::string > write_ion_variable_name (const std::string &name)
 Return ion variable name and corresponding ion write variable name. More...
 

Protected Attributes

std::unique_ptr< CodePrinterprinter
 Code printer object for target (C++) More...
 
std::string mod_filename
 Name of mod file (without .mod suffix) More...
 
std::string float_type = codegen::naming::DEFAULT_FLOAT_TYPE
 Data type of floating point variables. More...
 
bool optimize_ionvar_copies = true
 Flag to indicate if visitor should avoid ion variable copies. More...
 
codegen::CodegenInfo info
 All ast information for code generation. More...
 
symtab::SymbolTableprogram_symtab = nullptr
 Symbol table for the program. More...
 
std::vector< SymbolTypecodegen_float_variables
 All float variables for the model. More...
 
std::vector< IndexVariableInfocodegen_int_variables
 All int variables for the model. More...
 
std::vector< SymbolTypecodegen_global_variables
 All global variables for the model. More...
 
bool enable_variable_name_lookup = true
 Variable name should be converted to instance name (but not for function arguments) More...
 
bool printing_net_receive = false
 true if currently net_receive block being printed More...
 
bool printing_net_init = false
 true if currently initial block of net_receive being printed More...
 
bool printing_top_verbatim_blocks = false
 true if currently printing top level verbatim blocks More...
 
bool internal_method_call_encountered = false
 true if internal method call was encountered while processing verbatim block More...
 
int current_watch_statement = 0
 Index of watch statement being printed. More...
 

Member Typedef Documentation

◆ ParamVector

using nmodl::codegen::CodegenCppVisitor::ParamVector = std::vector<std::tuple<std::string, std::string, std::string, std::string> >
protected

A vector of parameters represented by a 4-tuple of strings:

  • type qualifier (e.g. const)
  • type (e.g. double)
  • pointer qualifier (e.g. __restrict__)
  • parameter name (e.g. data)

Definition at line 250 of file codegen_cpp_visitor.hpp.

◆ SymbolType

Definition at line 238 of file codegen_cpp_visitor.hpp.

Constructor & Destructor Documentation

◆ CodegenCppVisitor() [1/2]

nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor ( std::string  mod_filename,
const std::string &  output_dir,
std::string  float_type,
const bool  optimize_ionvar_copies,
size_t  blame_line = 0 
)
inline

Constructs the C++ code generator visitor.

This constructor instantiates an NMODL C++ code generator and allows writing generated code directly to a file in [output_dir]/[mod_filename].cpp.

Note
No code generation is performed at this stage. Since the code generator classes are all based on AstVisitor the AST must be visited using e.g. visit_program in order to generate the C++ code corresponding to the AST.
Parameters
mod_filenameThe name of the model for which code should be generated. It is used for constructing an output filename.
output_dirThe directory where target C++ file should be generated.
float_typeThe float type to use in the generated code. The string will be used as-is in the target code. This defaults to double.

Definition at line 198 of file codegen_cpp_visitor.hpp.

◆ CodegenCppVisitor() [2/2]

nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor ( std::string  mod_filename,
std::ostream &  stream,
std::string  float_type,
const bool  optimize_ionvar_copies,
size_t  blame_line = 0 
)
inline

Constructs the C++ code generator visitor.

This constructor instantiates an NMODL C++ code generator and allows writing generated code into an output stream.

Note
No code generation is performed at this stage. Since the code generator classes are all based on AstVisitor the AST must be visited using e.g. visit_program in order to generate the C++ code corresponding to the AST.
Parameters
mod_filenameThe name of the model for which code should be generated. It is used for constructing an output filename.
streamThe output stream onto which to write the generated code
float_typeThe float type to use in the generated code. The string will be used as-is in the target code. This defaults to double.

Definition at line 226 of file codegen_cpp_visitor.hpp.

Member Function Documentation

◆ add_escape_quote()

std::string nmodl::codegen::CodegenCppVisitor::add_escape_quote ( const std::string &  text) const
inlineprotected

Add quotes to string to be output.

Parameters
textThe string to be quoted
Returns
The same string with double-quotes pre- and postfixed

Definition at line 910 of file codegen_cpp_visitor.hpp.

◆ backend_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::backend_name ( ) const
protectedpure virtual

◆ breakpoint_current()

std::string nmodl::codegen::CodegenCppVisitor::breakpoint_current ( std::string  current) const
protected

Determine the variable name for the "current" used in breakpoint block taking into account intermediate code transformations.

Parameters
currentThe variable name for the current used in the model
Returns
The name for the current to be printed in C++

Current variable used in breakpoint block could be local variable. In this case, neuron has already renamed the variable name by prepending "_l". In our implementation, the variable could have been renamed by one of the pass. And hence, we search all local variables and check if the variable is renamed. Note that we have to look into the symbol table of statement block and not breakpoint.

Definition at line 350 of file codegen_cpp_visitor.cpp.

◆ breakpoint_exist()

bool nmodl::codegen::CodegenCppVisitor::breakpoint_exist ( ) const
protectednoexcept

Check if breakpoint node exist.

Definition at line 127 of file codegen_cpp_visitor.cpp.

◆ compute_method_name()

std::string nmodl::codegen::CodegenCppVisitor::compute_method_name ( BlockType  type) const
protected

Definition at line 1144 of file codegen_cpp_visitor.cpp.

◆ conc_write_statement()

virtual std::string nmodl::codegen::CodegenCppVisitor::conc_write_statement ( const std::string &  ion_name,
const std::string &  concentration,
int  index 
)
protectedpure virtual

Generate Function call statement for nrn_wrote_conc.

Parameters
ion_nameThe name of the ion variable
concentrationThe name of the concentration variable
index
Returns
The string representing the function call

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ default_float_data_type()

const char* nmodl::codegen::CodegenCppVisitor::default_float_data_type ( ) const
inlineprotectednoexcept

Default data type for floating point elements.

Definition at line 423 of file codegen_cpp_visitor.hpp.

◆ default_int_data_type()

const char* nmodl::codegen::CodegenCppVisitor::default_int_data_type ( ) const
inlineprotectednoexcept

Default data type for integer (offset) elements.

Definition at line 439 of file codegen_cpp_visitor.hpp.

◆ defined_method()

bool nmodl::codegen::CodegenCppVisitor::defined_method ( const std::string &  name) const
protected

Check if given method is defined in this model.

Parameters
nameThe name of the method to check
Returns
true if the method is defined

Definition at line 147 of file codegen_cpp_visitor.cpp.

◆ external_method_arguments()

virtual const char* nmodl::codegen::CodegenCppVisitor::external_method_arguments ( )
protectedpure virtualnoexcept

Arguments for external functions called from generated code.

Returns
A string representing the arguments passed to an external function

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ external_method_parameters()

virtual const char* nmodl::codegen::CodegenCppVisitor::external_method_parameters ( bool  table = false)
protectedpure virtualnoexcept

Parameters for functions in generated code that are called back from external code.

Functions registered in NEURON during initialization for callback must adhere to a prescribed calling convention. This method generates the string representing the function parameters for these externally called functions.

Parameters
table
Returns
A string representing the parameters of the function

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ float_data_type()

const std::string& nmodl::codegen::CodegenCppVisitor::float_data_type ( ) const
inlineprotectednoexcept

Data type for floating point elements specified on command line.

Definition at line 431 of file codegen_cpp_visitor.hpp.

◆ float_variable_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::float_variable_name ( const SymbolType symbol,
bool  use_instance 
) const
protectedpure virtual

Determine the name of a float variable given its symbol.

This function typically returns the accessor expression in backend code for the given symbol. Since the model variables are stored in data arrays and accessed by offset, this function will return the C++ string representing the array access at the correct offset

Parameters
symbolThe symbol of a variable for which we want to obtain its name
use_instanceShould the variable be accessed via instance or data array
Returns
The backend code string representing the access to the given variable symbol

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ float_variables_size()

int nmodl::codegen::CodegenCppVisitor::float_variables_size ( ) const
protected

Number of float variables in the model.

Definition at line 153 of file codegen_cpp_visitor.cpp.

◆ format_double_string()

std::string nmodl::codegen::CodegenCppVisitor::format_double_string ( const std::string &  s_value)
protected

Convert a given double value to its string representation.

Parameters
valueThe number to convert given as string as it is parsed by the modfile
Returns
Its string representation

We can directly print value but if user specify value as integer then then it gets printed as an integer. To avoid this, we use below wrapper. If user has provided integer then it gets printed as 1.0 (similar to mod2c and neuron where ".0" is appended). Otherwise we print double variables as they are represented in the mod file by user. If the value is in scientific representation (1e+20, 1E-15) then keep it as it is.

Definition at line 172 of file codegen_cpp_visitor.cpp.

◆ format_float_string()

std::string nmodl::codegen::CodegenCppVisitor::format_float_string ( const std::string &  value)
protected

Convert a given float value to its string representation.

Parameters
valueThe number to convert given as string as it is parsed by the modfile
Returns
Its string representation

Definition at line 177 of file codegen_cpp_visitor.cpp.

◆ get_channel_info_var_name()

std::string nmodl::codegen::CodegenCppVisitor::get_channel_info_var_name ( ) const
inlineprotectednoexcept

Name of channel info variable.

Definition at line 463 of file codegen_cpp_visitor.hpp.

◆ get_float_variables()

std::vector< CodegenCppVisitor::SymbolType > nmodl::codegen::CodegenCppVisitor::get_float_variables ( ) const
protected

Determine all float variables required during code generation.

Returns
A vector of float variables

Definition at line 932 of file codegen_cpp_visitor.cpp.

◆ get_int_variables()

std::vector< IndexVariableInfo > nmodl::codegen::CodegenCppVisitor::get_int_variables ( )
protected

Determine all int variables required during code generation.

IndexVariableInfo has following constructor arguments:

Returns
A vector of int variables
  • symbol
  • is_vdata (false)
  • is_index (false
  • is_integer (false)

Which variables are constant qualified?

  • node area is read only
  • read ion variables are read only
  • style_ionname is index / offset

note that this variable is not printed in neuron implementation

symbol for di_ion_dv var

insert after read/write variables but before style ion variable

Note
Variables for watch statements : there is one extra variable used in coreneuron compared to actual watch statements for compatibility with neuron (which uses one extra Datum variable)

Definition at line 998 of file codegen_cpp_visitor.cpp.

◆ get_parameter_str()

std::string nmodl::codegen::CodegenCppVisitor::get_parameter_str ( const ParamVector params)
staticprotected

Generate the string representing the procedure parameter declaration.

The procedure parameters are stored in a vector of 4-tuples each representing a parameter.

Parameters
paramsThe parameters that should be concatenated into the function parameter declaration
Returns
The string representing the declaration of function parameters

Definition at line 34 of file codegen_cpp_visitor.cpp.

◆ get_variable_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::get_variable_name ( const std::string &  name,
bool  use_instance = true 
) const
protectedpure virtual

Determine variable name in the structure of mechanism properties.

Parameters
nameVariable name that is being printed
use_instanceShould the variable be accessed via instance or data array
Returns
The C++ string representing the access to the variable in the neuron thread structure

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ global_struct()

std::string nmodl::codegen::CodegenCppVisitor::global_struct ( ) const
inlineprotected

Name of structure that wraps global variables.

Definition at line 385 of file codegen_cpp_visitor.hpp.

◆ global_struct_instance()

std::string nmodl::codegen::CodegenCppVisitor::global_struct_instance ( ) const
inlineprotected

Name of the (host-only) global instance of global_struct

Definition at line 393 of file codegen_cpp_visitor.hpp.

◆ global_variable_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::global_variable_name ( const SymbolType symbol,
bool  use_instance = true 
) const
protectedpure virtual

Determine the variable name for a global variable given its symbol.

Parameters
symbolThe symbol of a variable for which we want to obtain its name
use_instanceShould the variable be accessed via the (host-only) global variable or the instance-specific copy (also available on GPU).
Returns
The C++ string representing the access to the global variable

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ has_parameter_of_name()

template<typename T >
bool nmodl::codegen::CodegenCppVisitor::has_parameter_of_name ( const T &  node,
const std::string &  name 
)
protected

Check if function or procedure node has parameter with given name.

Template Parameters
TNode type (either procedure or function)
Parameters
nodeAST node (either procedure or function)
nameName of parameter
Returns
True if argument with name exist

Definition at line 54 of file codegen_cpp_visitor.cpp.

◆ instance_struct()

std::string nmodl::codegen::CodegenCppVisitor::instance_struct ( ) const
inlineprotected

Name of structure that wraps range variables.

Definition at line 370 of file codegen_cpp_visitor.hpp.

◆ int_variable_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::int_variable_name ( const IndexVariableInfo symbol,
const std::string &  name,
bool  use_instance 
) const
protectedpure virtual

Determine the name of an int variable given its symbol.

This function typically returns the accessor expression in backend code for the given symbol. Since the model variables are stored in data arrays and accessed by offset, this function will return the C++ string representing the array access at the correct offset

Parameters
symbolThe symbol of a variable for which we want to obtain its name
nameThe name of the index variable
use_instanceShould the variable be accessed via instance or data array
Returns
The backend code string representing the access to the given variable symbol

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ int_variables_size()

int nmodl::codegen::CodegenCppVisitor::int_variables_size ( ) const
protected

Number of integer variables in the model.

Definition at line 158 of file codegen_cpp_visitor.cpp.

◆ internal_method_arguments()

virtual std::string nmodl::codegen::CodegenCppVisitor::internal_method_arguments ( )
protectedpure virtual

Arguments for functions that are defined and used internally.

Returns
the method arguments

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ internal_method_parameters()

virtual ParamVector nmodl::codegen::CodegenCppVisitor::internal_method_parameters ( )
protectedpure virtual

Parameters for internally defined functions.

Returns
the method parameters

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ ion_read_statements()

std::vector< std::string > nmodl::codegen::CodegenCppVisitor::ion_read_statements ( BlockType  type) const
protected

For a given output block type, return statements for all read ion variables.

Parameters
typeThe type of code block being generated
Returns
A vector of strings representing the reading of ion variables

Depending upon the block type, we have to print read/write ion variables during code generation. Depending on block/procedure being printed, this method return statements as vector. As different code backends could have different variable names, we rely on backend-specific read_ion_variable_name and write_ion_variable_name method which will be overloaded.

Definition at line 223 of file codegen_cpp_visitor.cpp.

◆ ion_read_statements_optimized()

std::vector< std::string > nmodl::codegen::CodegenCppVisitor::ion_read_statements_optimized ( BlockType  type) const
protected

For a given output block type, return minimal statements for all read ion variables.

Parameters
typeThe type of code block being generated
Returns
A vector of strings representing the reading of ion variables

Definition at line 253 of file codegen_cpp_visitor.cpp.

◆ ion_variable_struct_required()

bool nmodl::codegen::CodegenCppVisitor::ion_variable_struct_required ( ) const
protected

Check if a structure for ion variables is required.

Returns
true if a structure fot ion variables must be generated

Definition at line 29 of file codegen_cpp_visitor.cpp.

◆ ion_write_statements()

std::vector< ShadowUseStatement > nmodl::codegen::CodegenCppVisitor::ion_write_statements ( BlockType  type)
protected

For a given output block type, return statements for writing back ion variables.

Parameters
typeThe type of code block being generated
Returns
A vector of strings representing the write-back of ion variables
Todo:
Unhandled case in neuron implementation

Definition at line 269 of file codegen_cpp_visitor.cpp.

◆ is_net_event()

bool nmodl::codegen::CodegenCppVisitor::is_net_event ( const std::string &  name) const
inlineprotectednoexcept

Checks if given function name is net_event.

Parameters
nameThe function name to check
Returns
true if the function is net_event

Definition at line 593 of file codegen_cpp_visitor.hpp.

◆ is_net_move()

bool nmodl::codegen::CodegenCppVisitor::is_net_move ( const std::string &  name) const
inlineprotectednoexcept

Checks if given function name is net_move.

Parameters
nameThe function name to check
Returns
true if the function is net_move

Definition at line 583 of file codegen_cpp_visitor.hpp.

◆ is_net_send()

bool nmodl::codegen::CodegenCppVisitor::is_net_send ( const std::string &  name) const
inlineprotectednoexcept

Checks if given function name is net_send.

Parameters
nameThe function name to check
Returns
true if the function is net_send

Definition at line 573 of file codegen_cpp_visitor.hpp.

◆ local_var_type()

const char* nmodl::codegen::CodegenCppVisitor::local_var_type ( ) const
inlineprotectednoexcept

Data type for the local variables.

Definition at line 407 of file codegen_cpp_visitor.hpp.

◆ make_symbol()

SymbolType nmodl::codegen::CodegenCppVisitor::make_symbol ( const std::string &  name) const
inlineprotected

Creates a temporary symbol.

Parameters
nameThe name of the symbol
Returns
A symbol based on the given name

Definition at line 930 of file codegen_cpp_visitor.hpp.

◆ method_name()

std::string nmodl::codegen::CodegenCppVisitor::method_name ( const std::string &  name) const
inlineprotected

Constructs the name of a function or procedure.

Parameters
nameThe name of the function or procedure
Returns
The name of the function or procedure postfixed with the model name

Definition at line 920 of file codegen_cpp_visitor.hpp.

◆ need_semicolon()

bool nmodl::codegen::CodegenCppVisitor::need_semicolon ( const ast::Statement node)
staticprotected

Check if a semicolon is required at the end of given statement.

Parameters
nodeThe AST Statement node to check
Returns
true if this Statement requires a semicolon

Statements like if, else etc. don't need semicolon at the end. (Note that it's valid to have "extraneous" semicolon). Also, statement block can appear as statement using expression statement which need to be inspected.

Definition at line 188 of file codegen_cpp_visitor.cpp.

◆ net_receive_buffering_required()

bool nmodl::codegen::CodegenCppVisitor::net_receive_buffering_required ( ) const
protectednoexcept

Check if net receive/send buffering kernels required.

Definition at line 104 of file codegen_cpp_visitor.cpp.

◆ net_receive_exist()

bool nmodl::codegen::CodegenCppVisitor::net_receive_exist ( ) const
protectednoexcept

Check if net_receive node exist.

Definition at line 122 of file codegen_cpp_visitor.cpp.

◆ net_receive_required()

bool nmodl::codegen::CodegenCppVisitor::net_receive_required ( ) const
protectednoexcept

Check if net_receive function is required.

Definition at line 132 of file codegen_cpp_visitor.cpp.

◆ net_send_buffer_required()

bool nmodl::codegen::CodegenCppVisitor::net_send_buffer_required ( ) const
protectednoexcept

Check if net_send_buffer is required.

Definition at line 94 of file codegen_cpp_visitor.cpp.

◆ nmodl_version()

std::string nmodl::codegen::CodegenCppVisitor::nmodl_version ( ) const
inlineprotectednoexcept

Return Nmodl language version.

Returns
A version

Definition at line 356 of file codegen_cpp_visitor.hpp.

◆ node_data_struct()

std::string nmodl::codegen::CodegenCppVisitor::node_data_struct ( ) const
inlineprotected

Name of structure that wraps node variables.

Definition at line 377 of file codegen_cpp_visitor.hpp.

◆ nrn_cur_required()

bool nmodl::codegen::CodegenCppVisitor::nrn_cur_required ( ) const
protectednoexcept

Check if nrn_cur function is required.

Definition at line 117 of file codegen_cpp_visitor.cpp.

◆ nrn_state_required()

bool nmodl::codegen::CodegenCppVisitor::nrn_state_required ( ) const
protectednoexcept

Check if nrn_state function is required.

Definition at line 109 of file codegen_cpp_visitor.cpp.

◆ nrn_thread_arguments()

virtual std::string nmodl::codegen::CodegenCppVisitor::nrn_thread_arguments ( ) const
protectedpure virtual

Arguments for "_threadargs_" macro in neuron implementation.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ nrn_thread_internal_arguments()

virtual std::string nmodl::codegen::CodegenCppVisitor::nrn_thread_internal_arguments ( )
protectedpure virtual

Arguments for "_threadargs_" macro in neuron implementation.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ operator_for_d()

const char* nmodl::codegen::CodegenCppVisitor::operator_for_d ( ) const
inlineprotectednoexcept

Operator for diagonal vector update (matrix update)

Definition at line 455 of file codegen_cpp_visitor.hpp.

◆ operator_for_rhs()

const char* nmodl::codegen::CodegenCppVisitor::operator_for_rhs ( ) const
inlineprotectednoexcept

Operator for rhs vector update (matrix update)

Definition at line 447 of file codegen_cpp_visitor.hpp.

◆ optimize_ion_variable_copies()

virtual bool nmodl::codegen::CodegenCppVisitor::optimize_ion_variable_copies ( ) const
protectedpure virtual

Check if ion variable copies should be avoided.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ position_of_float_var()

virtual int nmodl::codegen::CodegenCppVisitor::position_of_float_var ( const std::string &  name) const
protectedpure virtual

Determine the position in the data array for a given float variable.

Parameters
nameThe name of a float variable
Returns
The position index in the data array

Implemented in nmodl::codegen::CodegenNeuronCppVisitor, and nmodl::codegen::CodegenCoreneuronCppVisitor.

◆ position_of_int_var()

virtual int nmodl::codegen::CodegenCppVisitor::position_of_int_var ( const std::string &  name) const
protectedpure virtual

Determine the position in the data array for a given int variable.

Parameters
nameThe name of an int variable
Returns
The position index in the data array

Implemented in nmodl::codegen::CodegenNeuronCppVisitor, and nmodl::codegen::CodegenCoreneuronCppVisitor.

◆ print_atomic_reduction_pragma()

virtual void nmodl::codegen::CodegenCppVisitor::print_atomic_reduction_pragma ( )
protectedpure virtual

Print atomic update pragma for reduction statements.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, nmodl::codegen::CodegenNeuronCppVisitor, and nmodl::codegen::CodegenAccVisitor.

◆ print_backend_info()

virtual void nmodl::codegen::CodegenCppVisitor::print_backend_info ( )
protectedpure virtual

Print top file header printed in generated code.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_codegen_routines()

virtual void nmodl::codegen::CodegenCppVisitor::print_codegen_routines ( )
protectedpure virtual

Print entry point to code generation.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_compute_functions()

virtual void nmodl::codegen::CodegenCppVisitor::print_compute_functions ( )
protectedpure virtual

Print all compute functions for every backend.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_data_structures()

virtual void nmodl::codegen::CodegenCppVisitor::print_data_structures ( bool  print_initializers)
protectedpure virtual

Print all classes.

Parameters
print_initializersWhether to include default values.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_fast_imem_calculation()

virtual void nmodl::codegen::CodegenCppVisitor::print_fast_imem_calculation ( )
protectedpure virtual

◆ print_function()

virtual void nmodl::codegen::CodegenCppVisitor::print_function ( const ast::FunctionBlock node)
protectedpure virtual

Print NMODL function in target backend code.

Parameters
node

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_function_call()

void nmodl::codegen::CodegenCppVisitor::print_function_call ( const ast::FunctionCall node)
protectedvirtual

Print call to internal or external function.

Parameters
nodeThe AST node representing a function call

Definition at line 425 of file codegen_cpp_visitor.cpp.

◆ print_function_or_procedure()

virtual void nmodl::codegen::CodegenCppVisitor::print_function_or_procedure ( const ast::Block node,
const std::string &  name 
)
protectedpure virtual

Print nmodl function or procedure (common code)

Parameters
nodethe AST node representing the function or procedure in NMODL
namethe name of the function or procedure

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_function_procedure_helper()

virtual void nmodl::codegen::CodegenCppVisitor::print_function_procedure_helper ( const ast::Block node)
protectedpure virtual

Common helper function to help printing function or procedure blocks.

Parameters
nodethe AST node representing the function or procedure in NMODL

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_function_prototypes()

virtual void nmodl::codegen::CodegenCppVisitor::print_function_prototypes ( )
protectedpure virtual

Print function and procedures prototype declaration.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_g_unused()

virtual void nmodl::codegen::CodegenCppVisitor::print_g_unused ( ) const
protectedpure virtual

Set g_unused (conductance) for NRN_PRCELLSTATE feature.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_global_function_common_code()

virtual void nmodl::codegen::CodegenCppVisitor::print_global_function_common_code ( BlockType  type,
const std::string &  function_name = "" 
)
protectedpure virtual

Print common code for global functions like nrn_init, nrn_cur and nrn_state.

Parameters
typeThe target backend code block type

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_global_var_struct_assertions()

void nmodl::codegen::CodegenCppVisitor::print_global_var_struct_assertions ( ) const
protectedvirtual

Print static assertions about the global variable struct.

Definition at line 407 of file codegen_cpp_visitor.cpp.

◆ print_global_var_struct_decl()

void nmodl::codegen::CodegenCppVisitor::print_global_var_struct_decl ( )
protectedvirtual

Instantiate global var instance.

For C++ code generation this is empty

Returns
""

Definition at line 420 of file codegen_cpp_visitor.cpp.

◆ print_global_variables_for_hoc()

virtual void nmodl::codegen::CodegenCppVisitor::print_global_variables_for_hoc ( )
protectedpure virtual

Print byte arrays that register scalar and vector variables for hoc interface.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_headers_include()

virtual void nmodl::codegen::CodegenCppVisitor::print_headers_include ( )
protectedpure virtual

◆ print_mechanism_global_var_structure()

virtual void nmodl::codegen::CodegenCppVisitor::print_mechanism_global_var_structure ( bool  print_initializers)
protectedpure virtual

Print the structure that wraps all global variables used in the NMODL.

Parameters
print_initializersWhether to include default values in the struct definition (true: int foo{42}; false: int foo;)

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_mechanism_info()

void nmodl::codegen::CodegenCppVisitor::print_mechanism_info ( )
protected

Print backend code for byte array that has mechanism information (to be registered with NEURON/CoreNEURON)

Definition at line 488 of file codegen_cpp_visitor.cpp.

◆ print_mechanism_range_var_structure()

virtual void nmodl::codegen::CodegenCppVisitor::print_mechanism_range_var_structure ( bool  print_initializers)
pure virtual

Print the structure that wraps all range and int variables required for the NMODL.

Parameters
print_initializersWhether or not default values for variables be included in the struct declaration.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_mechanism_register()

virtual void nmodl::codegen::CodegenCppVisitor::print_mechanism_register ( )
protectedpure virtual

Print the mechanism registration function.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_namespace_begin()

virtual void nmodl::codegen::CodegenCppVisitor::print_namespace_begin ( )
protectedpure virtual

◆ print_namespace_end()

virtual void nmodl::codegen::CodegenCppVisitor::print_namespace_end ( )
protectedpure virtual

◆ print_namespace_start()

virtual void nmodl::codegen::CodegenCppVisitor::print_namespace_start ( )
protectedpure virtual

Prints the start of the simulator namespace.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_namespace_stop()

virtual void nmodl::codegen::CodegenCppVisitor::print_namespace_stop ( )
protectedpure virtual

Prints the end of the simulator namespace.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_net_event_call()

virtual void nmodl::codegen::CodegenCppVisitor::print_net_event_call ( const ast::FunctionCall node)
protectedpure virtual

Print call to net_event.

Parameters
nodeThe AST node representing the function call

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_net_move_call()

virtual void nmodl::codegen::CodegenCppVisitor::print_net_move_call ( const ast::FunctionCall node)
protectedpure virtual

Print call to net_move.

Parameters
nodeThe AST node representing the function call

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_net_send_call()

virtual void nmodl::codegen::CodegenCppVisitor::print_net_send_call ( const ast::FunctionCall node)
protectedpure virtual

Print call to net_send.

Parameters
nodeThe AST node representing the function call

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nmodl_constants()

void nmodl::codegen::CodegenCppVisitor::print_nmodl_constants ( )
protected

Print the nmodl constants used in backend code.

NMODL constants from unit database.

Currently we define three basic constants, which are assumed to be present in NMODL, directly in the backend code:

static const double FARADAY = 96485.3;
static const double PI = 3.14159;
static const double R = 8.3145;

Definition at line 593 of file codegen_cpp_visitor.cpp.

◆ print_nrn_alloc()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_alloc ( )
protectedpure virtual

Print nrn_alloc function definition.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_constructor()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_constructor ( )
protectedpure virtual

Print nrn_constructor function definition.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_cur()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_cur ( )
protectedpure virtual

Print nrn_cur / current update function definition.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_cur_conductance_kernel()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_cur_conductance_kernel ( const ast::BreakpointBlock node)
protectedpure virtual

Print the nrn_cur kernel with NMODL conductance keyword provisions.

If the NMODL conductance keyword is used in the breakpoint block, then CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer

Parameters
nodethe AST node representing the NMODL breakpoint block

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_cur_kernel()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_cur_kernel ( const ast::BreakpointBlock node)
protectedpure virtual

Print main body of nrn_cur function.

Parameters
nodethe AST node representing the NMODL breakpoint block

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_cur_non_conductance_kernel()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_cur_non_conductance_kernel ( )
protectedpure virtual

Print the nrn_cur kernel without NMODL conductance keyword provisions.

If the NMODL conductance keyword is not used in the breakpoint block, then CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_current()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_current ( const ast::BreakpointBlock node)
protectedpure virtual

Print the nrn_current kernel.

Note
nrn_cur_kernel will have two calls to nrn_current if no conductance keywords specified
Parameters
nodethe AST node representing the NMODL breakpoint block

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_destructor()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_destructor ( )
protectedpure virtual

Print nrn_destructor function definition.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_nrn_state()

virtual void nmodl::codegen::CodegenCppVisitor::print_nrn_state ( )
protectedpure virtual

Print nrn_state / state update function definition.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_prcellstate_macros()

void nmodl::codegen::CodegenCppVisitor::print_prcellstate_macros ( ) const
protected

Print declaration of macro NRN_PRCELLSTATE for debugging.

Definition at line 481 of file codegen_cpp_visitor.cpp.

◆ print_procedure()

virtual void nmodl::codegen::CodegenCppVisitor::print_procedure ( const ast::ProcedureBlock node)
protectedpure virtual

Print NMODL procedure in target backend code.

Parameters
node

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_sdlists_init()

virtual void nmodl::codegen::CodegenCppVisitor::print_sdlists_init ( bool  print_initializers)
protectedpure virtual

◆ print_standard_includes()

virtual void nmodl::codegen::CodegenCppVisitor::print_standard_includes ( )
protectedpure virtual

Print standard C/C++ includes.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ print_statement_block()

void nmodl::codegen::CodegenCppVisitor::print_statement_block ( const ast::StatementBlock node,
bool  open_brace = true,
bool  close_brace = true 
)
protected

Print any statement block in nmodl with option to (not) print braces.

The individual statements (of type nmodl::ast::Statement) in the StatementBlock are printed by accepting this visistor.

Parameters
nodeA (possibly empty) statement block AST node
open_bracePrint an opening brace if false
close_bracePrint a closing brace if true

not necessary to add indent for verbatim block (pretty-printing)

Definition at line 526 of file codegen_cpp_visitor.cpp.

◆ print_v_unused()

virtual void nmodl::codegen::CodegenCppVisitor::print_v_unused ( ) const
protectedpure virtual

Set v_unused (voltage) for NRN_PRCELLSTATE feature.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ process_shadow_update_statement()

std::string nmodl::codegen::CodegenCppVisitor::process_shadow_update_statement ( const ShadowUseStatement statement,
BlockType  type 
)
protected

Process shadow update statement.

If mechanisms dependency level execution is enabled then certain updates like ionic current contributions needs to be atomically updated.

If the statement requires reduction then add it to vector of reduction statement and return statement using shadow update

Parameters
statementThe statement that might require shadow updates
typeThe target backend code block type
Returns
The generated target backend code

In this case we first update current mechanism's shadow vector and then add statement to queue that will be used in reduction queue.

Definition at line 327 of file codegen_cpp_visitor.cpp.

◆ process_verbatim_text()

virtual std::string nmodl::codegen::CodegenCppVisitor::process_verbatim_text ( std::string const &  text)
protectedpure virtual

Process a verbatim block for possible variable renaming.

Parameters
textThe verbatim code to be processed
Returns
The code with all variables renamed as needed

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ range_variable_setup_required()

bool nmodl::codegen::CodegenCppVisitor::range_variable_setup_required ( ) const
protectednoexcept

Check if setup_range_variable function is required.

Returns

When floating point data type is not default (i.e. double) then we have to copy old array to new type (for range variables).

Definition at line 141 of file codegen_cpp_visitor.cpp.

◆ read_ion_variable_name()

std::pair< std::string, std::string > nmodl::codegen::CodegenCppVisitor::read_ion_variable_name ( const std::string &  name)
staticprotected

Return ion variable name and corresponding ion read variable name.

Example: {"ena", "ion_ena"} = read_ion_variable_name("ena");

Parameters
nameThe ion variable name
Returns
The ion read variable name

Definition at line 390 of file codegen_cpp_visitor.cpp.

◆ register_mechanism_arguments()

virtual std::string nmodl::codegen::CodegenCppVisitor::register_mechanism_arguments ( ) const
protectedpure virtual

Arguments for register_mech or point_register_mech function.

Implemented in nmodl::codegen::CodegenCoreneuronCppVisitor, and nmodl::codegen::CodegenNeuronCppVisitor.

◆ rename_function_arguments()

void nmodl::codegen::CodegenCppVisitor::rename_function_arguments ( )
protected

Rename function/procedure arguments that conflict with default arguments.

Todo:
Issue with verbatim renaming.

e.g. pattern.mod has info struct with index variable. If we use "index" instead of "indexes" as default argument then during verbatim replacement we don't know the index is which one. This is because verbatim renaming pass has already stripped out prefixes from the text.

Definition at line 565 of file codegen_cpp_visitor.cpp.

◆ setup()

void nmodl::codegen::CodegenCppVisitor::setup ( const ast::Program node)

Setup the target backend code generator.

Typically called from within visit_program but may be called from specialized targets to setup this Code generator as fallback.

Definition at line 1123 of file codegen_cpp_visitor.cpp.

◆ simulator_name()

virtual std::string nmodl::codegen::CodegenCppVisitor::simulator_name ( )
protectedpure virtual

Name of the simulator the code was generated for.

Implemented in nmodl::codegen::CodegenNeuronCppVisitor, and nmodl::codegen::CodegenCoreneuronCppVisitor.

◆ statement_to_skip()

bool nmodl::codegen::CodegenCppVisitor::statement_to_skip ( const ast::Statement node)
staticprotected

Check if given statement should be skipped during code generation.

Parameters
nodeThe AST Statement node to check
Returns
true if this Statement is to be skipped

Certain statements like unit, comment, solve can/need to be skipped during code generation. Note that solve block is wrapped in expression statement and hence we have to check inner expression. It's also true for the initial block defined inside net receive block.

Definition at line 70 of file codegen_cpp_visitor.cpp.

◆ update_if_ion_variable_name()

std::string nmodl::codegen::CodegenCppVisitor::update_if_ion_variable_name ( const std::string &  name) const
protected

Determine the updated name if the ion variable has been optimized.

Parameters
nameThe ion variable name
Returns
The updated name of the variable has been optimized (e.g. ena --> ion_ena)

Definition at line 373 of file codegen_cpp_visitor.cpp.

◆ update_index_semantics()

void nmodl::codegen::CodegenCppVisitor::update_index_semantics ( )
protected

populate all index semantics needed for registration with coreneuron

Once variables are populated, update index semantics to register with coreneuron

add if variable is not present in the read list

Definition at line 856 of file codegen_cpp_visitor.cpp.

◆ visit_binary_expression()

void nmodl::codegen::CodegenCppVisitor::visit_binary_expression ( const ast::BinaryExpression node)
overrideprotectedvirtual

visit node of type ast::BinaryExpression

Implements nmodl::visitor::ConstVisitor.

Definition at line 759 of file codegen_cpp_visitor.cpp.

◆ visit_binary_operator()

void nmodl::codegen::CodegenCppVisitor::visit_binary_operator ( const ast::BinaryOperator node)
overrideprotectedvirtual

visit node of type ast::BinaryOperator

Implements nmodl::visitor::ConstVisitor.

Definition at line 777 of file codegen_cpp_visitor.cpp.

◆ visit_boolean()

void nmodl::codegen::CodegenCppVisitor::visit_boolean ( const ast::Boolean node)
overrideprotectedvirtual

visit node of type ast::Boolean

Implements nmodl::visitor::ConstVisitor.

Definition at line 638 of file codegen_cpp_visitor.cpp.

◆ visit_double()

void nmodl::codegen::CodegenCppVisitor::visit_double ( const ast::Double node)
overrideprotectedvirtual

visit node of type ast::Double

Implements nmodl::visitor::ConstVisitor.

Definition at line 633 of file codegen_cpp_visitor.cpp.

◆ visit_else_if_statement()

void nmodl::codegen::CodegenCppVisitor::visit_else_if_statement ( const ast::ElseIfStatement node)
overrideprotectedvirtual

visit node of type ast::ElseIfStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 709 of file codegen_cpp_visitor.cpp.

◆ visit_else_statement()

void nmodl::codegen::CodegenCppVisitor::visit_else_statement ( const ast::ElseStatement node)
overrideprotectedvirtual

visit node of type ast::ElseStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 717 of file codegen_cpp_visitor.cpp.

◆ visit_float()

void nmodl::codegen::CodegenCppVisitor::visit_float ( const ast::Float node)
overrideprotectedvirtual

visit node of type ast::Float

Implements nmodl::visitor::ConstVisitor.

Definition at line 628 of file codegen_cpp_visitor.cpp.

◆ visit_from_statement()

void nmodl::codegen::CodegenCppVisitor::visit_from_statement ( const ast::FromStatement node)
overrideprotectedvirtual

visit node of type ast::FromStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 731 of file codegen_cpp_visitor.cpp.

◆ visit_function_call()

void nmodl::codegen::CodegenCppVisitor::visit_function_call ( const ast::FunctionCall node)
overrideprotectedvirtual

visit node of type ast::FunctionCall

Implements nmodl::visitor::ConstVisitor.

Definition at line 797 of file codegen_cpp_visitor.cpp.

◆ visit_if_statement()

void nmodl::codegen::CodegenCppVisitor::visit_if_statement ( const ast::IfStatement node)
overrideprotectedvirtual

visit node of type ast::IfStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 696 of file codegen_cpp_visitor.cpp.

◆ visit_indexed_name()

void nmodl::codegen::CodegenCppVisitor::visit_indexed_name ( const ast::IndexedName node)
overrideprotectedvirtual

visit node of type ast::IndexedName

Implements nmodl::visitor::ConstVisitor.

Definition at line 680 of file codegen_cpp_visitor.cpp.

◆ visit_integer()

void nmodl::codegen::CodegenCppVisitor::visit_integer ( const ast::Integer node)
overrideprotectedvirtual

visit node of type ast::Integer

Implements nmodl::visitor::ConstVisitor.

Definition at line 622 of file codegen_cpp_visitor.cpp.

◆ visit_local_list_statement()

void nmodl::codegen::CodegenCppVisitor::visit_local_list_statement ( const ast::LocalListStatement node)
overrideprotectedvirtual

visit node of type ast::LocalListStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 690 of file codegen_cpp_visitor.cpp.

◆ visit_mutex_lock()

void nmodl::codegen::CodegenCppVisitor::visit_mutex_lock ( const ast::MutexLock node)
overrideprotectedvirtual

visit node of type ast::MutexLock

Implements nmodl::visitor::ConstVisitor.

Definition at line 829 of file codegen_cpp_visitor.cpp.

◆ visit_mutex_unlock()

void nmodl::codegen::CodegenCppVisitor::visit_mutex_unlock ( const ast::MutexUnlock node)
overrideprotectedvirtual

visit node of type ast::MutexUnlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 836 of file codegen_cpp_visitor.cpp.

◆ visit_name()

void nmodl::codegen::CodegenCppVisitor::visit_name ( const ast::Name node)
overrideprotectedvirtual

visit node of type ast::Name

Implements nmodl::visitor::ConstVisitor.

Definition at line 643 of file codegen_cpp_visitor.cpp.

◆ visit_paren_expression()

void nmodl::codegen::CodegenCppVisitor::visit_paren_expression ( const ast::ParenExpression node)
overrideprotectedvirtual

visit node of type ast::ParenExpression

Implements nmodl::visitor::ConstVisitor.

Definition at line 752 of file codegen_cpp_visitor.cpp.

◆ visit_prime_name()

void nmodl::codegen::CodegenCppVisitor::visit_prime_name ( const ast::PrimeName node)
overrideprotectedvirtual

visit node of type ast::PrimeName

Implements nmodl::visitor::ConstVisitor.

Definition at line 653 of file codegen_cpp_visitor.cpp.

◆ visit_program()

void nmodl::codegen::CodegenCppVisitor::visit_program ( const ast::Program program)
overridevirtual

Main and only member function to call after creating an instance of this class.

Parameters
programthe AST to translate to C++ code

Implements nmodl::visitor::ConstVisitor.

Definition at line 1167 of file codegen_cpp_visitor.cpp.

◆ visit_protect_statement()

void nmodl::codegen::CodegenCppVisitor::visit_protect_statement ( const ast::ProtectStatement node)
overrideprotectedvirtual

visit node of type ast::ProtectStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 821 of file codegen_cpp_visitor.cpp.

◆ visit_solution_expression()

void nmodl::codegen::CodegenCppVisitor::visit_solution_expression ( const ast::SolutionExpression node)
overrideprotectedvirtual

visit node of type ast::SolutionExpression

Implements nmodl::visitor::ConstVisitor.

Definition at line 841 of file codegen_cpp_visitor.cpp.

◆ visit_statement_block()

void nmodl::codegen::CodegenCppVisitor::visit_statement_block ( const ast::StatementBlock node)
overrideprotectedvirtual

Statement block is top level construct (for every nmodl block). Sometime we want to analyse ast nodes even if code generation is false. Hence we visit children even if code generation is false.

Implements nmodl::visitor::ConstVisitor.

Definition at line 792 of file codegen_cpp_visitor.cpp.

◆ visit_string()

void nmodl::codegen::CodegenCppVisitor::visit_string ( const ast::String node)
overrideprotectedvirtual

visit node of type ast::String

Implements nmodl::visitor::ConstVisitor.

Definition at line 613 of file codegen_cpp_visitor.cpp.

◆ visit_unary_operator()

void nmodl::codegen::CodegenCppVisitor::visit_unary_operator ( const ast::UnaryOperator node)
overrideprotectedvirtual

visit node of type ast::UnaryOperator

Implements nmodl::visitor::ConstVisitor.

Definition at line 782 of file codegen_cpp_visitor.cpp.

◆ visit_unit()

void nmodl::codegen::CodegenCppVisitor::visit_unit ( const ast::Unit node)
overrideprotectedvirtual

visit node of type ast::Unit

Implements nmodl::visitor::ConstVisitor.

Definition at line 648 of file codegen_cpp_visitor.cpp.

◆ visit_update_dt()

void nmodl::codegen::CodegenCppVisitor::visit_update_dt ( const ast::UpdateDt node)
overrideprotectedvirtual

visit node of type ast::UpdateDt

Implements nmodl::visitor::ConstVisitor.

Definition at line 816 of file codegen_cpp_visitor.cpp.

◆ visit_var_name()

void nmodl::codegen::CodegenCppVisitor::visit_var_name ( const ast::VarName node)
overrideprotectedvirtual
Todo:
: Validate how @ is being handled in neuron implementation

Implements nmodl::visitor::ConstVisitor.

Definition at line 661 of file codegen_cpp_visitor.cpp.

◆ visit_verbatim()

void nmodl::codegen::CodegenCppVisitor::visit_verbatim ( const ast::Verbatim node)
overrideprotectedvirtual

visit node of type ast::Verbatim

Implements nmodl::visitor::ConstVisitor.

Definition at line 802 of file codegen_cpp_visitor.cpp.

◆ visit_while_statement()

void nmodl::codegen::CodegenCppVisitor::visit_while_statement ( const ast::WhileStatement node)
overrideprotectedvirtual

visit node of type ast::WhileStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 723 of file codegen_cpp_visitor.cpp.

◆ write_ion_variable_name()

std::pair< std::string, std::string > nmodl::codegen::CodegenCppVisitor::write_ion_variable_name ( const std::string &  name)
staticprotected

Return ion variable name and corresponding ion write variable name.

Example: {"ion_ena", "ena"} = write_ion_variable_name("ena");

Parameters
nameThe ion variable name
Returns
The ion write variable name

Definition at line 396 of file codegen_cpp_visitor.cpp.

Member Data Documentation

◆ codegen_float_variables

std::vector<SymbolType> nmodl::codegen::CodegenCppVisitor::codegen_float_variables
protected

All float variables for the model.

Definition at line 296 of file codegen_cpp_visitor.hpp.

◆ codegen_global_variables

std::vector<SymbolType> nmodl::codegen::CodegenCppVisitor::codegen_global_variables
protected

All global variables for the model.

Todo:
: this has become different than CodegenInfo

Definition at line 309 of file codegen_cpp_visitor.hpp.

◆ codegen_int_variables

std::vector<IndexVariableInfo> nmodl::codegen::CodegenCppVisitor::codegen_int_variables
protected

All int variables for the model.

Definition at line 302 of file codegen_cpp_visitor.hpp.

◆ current_watch_statement

int nmodl::codegen::CodegenCppVisitor::current_watch_statement = 0
protected

Index of watch statement being printed.

Definition at line 345 of file codegen_cpp_visitor.hpp.

◆ enable_variable_name_lookup

bool nmodl::codegen::CodegenCppVisitor::enable_variable_name_lookup = true
protected

Variable name should be converted to instance name (but not for function arguments)

Definition at line 315 of file codegen_cpp_visitor.hpp.

◆ float_type

std::string nmodl::codegen::CodegenCppVisitor::float_type = codegen::naming::DEFAULT_FLOAT_TYPE
protected

Data type of floating point variables.

Definition at line 272 of file codegen_cpp_visitor.hpp.

◆ info

codegen::CodegenInfo nmodl::codegen::CodegenCppVisitor::info
protected

All ast information for code generation.

Definition at line 284 of file codegen_cpp_visitor.hpp.

◆ internal_method_call_encountered

bool nmodl::codegen::CodegenCppVisitor::internal_method_call_encountered = false
protected

true if internal method call was encountered while processing verbatim block

Definition at line 339 of file codegen_cpp_visitor.hpp.

◆ mod_filename

std::string nmodl::codegen::CodegenCppVisitor::mod_filename
protected

Name of mod file (without .mod suffix)

Definition at line 266 of file codegen_cpp_visitor.hpp.

◆ optimize_ionvar_copies

bool nmodl::codegen::CodegenCppVisitor::optimize_ionvar_copies = true
protected

Flag to indicate if visitor should avoid ion variable copies.

Definition at line 278 of file codegen_cpp_visitor.hpp.

◆ printer

std::unique_ptr<CodePrinter> nmodl::codegen::CodegenCppVisitor::printer
protected

Code printer object for target (C++)

Definition at line 260 of file codegen_cpp_visitor.hpp.

◆ printing_net_init

bool nmodl::codegen::CodegenCppVisitor::printing_net_init = false
protected

true if currently initial block of net_receive being printed

Definition at line 327 of file codegen_cpp_visitor.hpp.

◆ printing_net_receive

bool nmodl::codegen::CodegenCppVisitor::printing_net_receive = false
protected

true if currently net_receive block being printed

Definition at line 321 of file codegen_cpp_visitor.hpp.

◆ printing_top_verbatim_blocks

bool nmodl::codegen::CodegenCppVisitor::printing_top_verbatim_blocks = false
protected

true if currently printing top level verbatim blocks

Definition at line 333 of file codegen_cpp_visitor.hpp.

◆ program_symtab

symtab::SymbolTable* nmodl::codegen::CodegenCppVisitor::program_symtab = nullptr
protected

Symbol table for the program.

Definition at line 290 of file codegen_cpp_visitor.hpp.


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