User Guide
nmodl Namespace Reference

encapsulates code generation backend implementations More...

Detailed Description

encapsulates code generation backend implementations

THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.

encapsulates everything related to NMODL code generation framework

Namespaces

 ast
 Abstract Syntax Tree (AST) related implementations.
 
 codegen
 
 crout
 
 details
 details of lexer tokens
 
 docstring
 docstring of Python exposed API
 
 newton
 newton solver implementations
 
 parser
 encapsulate lexer and parsers implementations
 
 printer
 implementation of various printers
 
 pybind_wrappers
 
 stringutils
 string utility functions
 
 symtab
 Symbol table related implementations
 
 test_utils
 custom type to represent nmodl construct for testing
 
 units
 encapsulates unit database and tables implementation
 
 utils
 file/string manipulation functions
 
 visitor
 Implementation of different AST visitors.
 

Classes

struct  CMakeInfo
 
class  CodegenTransformVisitor
 Visitor to make last transformation to AST before codegen. More...
 
class  FileLibrary
 Manage search path. More...
 
struct  Logger
 Logger implementation based on spdlog. More...
 
class  ModToken
 Represent token returned by scanner. More...
 
struct  NrnUnitsLib
 Information of units database i.e. More...
 
class  PyNmodlDriver
 Class to bridge C++ NmodlDriver with Python world using pybind11. More...
 
struct  Version
 Project version information. More...
 

Typedefs

using LocationType = nmodl::parser::location
 
using Parser = parser::NmodlParser
 
using PositionType = parser::location
 
using SymbolType = parser::NmodlParser::symbol_type
 
using Token = parser::NmodlParser::token
 
using TokenType = parser::NmodlParser::token_type
 
using logger_type = std::shared_ptr< spdlog::logger >
 

Functions

std::ostream & operator<< (std::ostream &stream, const ModToken &mt)
 
ModToken operator+ (ModToken const &adder1, ModToken const &adder2)
 
SymbolType double_symbol (const std::string &value, PositionType &pos)
 Create a symbol for ast::Double AST class. More...
 
SymbolType integer_symbol (int value, PositionType &pos, const char *text)
 Create a symbol for ast::Integer AST. More...
 
SymbolType name_symbol (const std::string &text, PositionType &pos, TokenType type)
 Create symbol for ast::Name AST class. More...
 
SymbolType prime_symbol (std::string text, PositionType &pos)
 Create symbol for ast::Prime AST class. More...
 
SymbolType string_symbol (const std::string &text, PositionType &pos)
 Create symbol for ast::String AST class. More...
 
SymbolType token_symbol (const std::string &key, PositionType &pos, TokenType type)
 Create symbol for AST class. More...
 
bool is_keyword (const std::string &name)
 Check if given name is a keyword in NMODL. More...
 
bool is_method (const std::string &name)
 Check if given name is an integration method in NMODL. More...
 
TokenType token_type (const std::string &name)
 Return token type for given token name. More...
 
std::vector< std::string > get_external_variables ()
 Return variables declared in NEURON that are available to NMODL. More...
 
std::vector< std::string > get_external_functions ()
 Return functions that can be used in the NMODL. More...
 
std::vector< std::shared_ptr< const ast::Ast > > collect_nodes (const ast::Ast &node, const std::vector< ast::AstNodeType > &types={})
 traverse node recursively and collect nodes of given types More...
 
std::vector< std::shared_ptr< ast::Ast > > collect_nodes (ast::Ast &node, const std::vector< ast::AstNodeType > &types={})
 traverse node recursively and collect nodes of given types More...
 
bool sparse_solver_exists (const ast::Ast &node)
 
std::string to_nmodl (const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types={})
 Given AST node, return the NMODL string representation. More...
 
std::string to_json (const ast::Ast &node, bool compact=false, bool expand=false, bool add_nmodl=false)
 Given AST node, return the JSON string representation. More...
 
std::pair< std::string, std::unordered_set< std::string > > statement_dependencies (const std::shared_ptr< ast::Expression > &lhs, const std::shared_ptr< ast::Expression > &rhs)
 If lhs and rhs combined represent an assignment (we assume to have an "=" in between them) we extract the variables on which the assigned variable depends on. More...
 
std::string get_indexed_name (const ast::IndexedName &node)
 Given a Indexed node, return the name with index. More...
 
std::string get_full_var_name (const ast::VarName &node)
 Given a VarName node, return the full var name including index. More...
 
bool is_random_construct_function (const std::string &name)
 Is given name a one of the function for RANDOM construct. More...
 
template<typename T >
std::enable_if< std::is_base_of< ast::Ast, T >::value, std::string >::type to_nmodl (const std::shared_ptr< T > &node, const std::set< ast::AstNodeType > &exclude_types={})
 Given a shared pointer to an AST node, return the NMODL string representation. More...
 

Variables

Logger nmodl_logger ("NMODL", "[%n] [%^%l%$] :: %v")
 
logger_type logger = nmodl_logger.logger
 

Typedef Documentation

◆ LocationType

using nmodl::LocationType = typedef nmodl::parser::location

Definition at line 12 of file modtoken.cpp.

◆ logger_type

typedef std::shared_ptr< spdlog::logger > nmodl::logger_type

Definition at line 19 of file logger.cpp.

◆ Parser

using nmodl::Parser = typedef parser::NmodlParser

Definition at line 19 of file nmodl_utils.cpp.

◆ PositionType

using nmodl::PositionType = typedef parser::location

Definition at line 25 of file nmodl_utils.hpp.

◆ SymbolType

Definition at line 26 of file nmodl_utils.hpp.

◆ Token

typedef parser::NmodlParser::token nmodl::Token

Definition at line 27 of file nmodl_utils.hpp.

◆ TokenType

typedef parser::NmodlParser::token_type nmodl::TokenType

Definition at line 28 of file nmodl_utils.hpp.

Function Documentation

◆ collect_nodes() [1/2]

std::vector< std::shared_ptr< ast::Ast > > nmodl::collect_nodes ( ast::Ast node,
const std::vector< ast::AstNodeType > &  types 
)

traverse node recursively and collect nodes of given types

Definition at line 212 of file visitor_utils.cpp.

◆ collect_nodes() [2/2]

std::vector< std::shared_ptr< const ast::Ast > > nmodl::collect_nodes ( const ast::Ast node,
const std::vector< ast::AstNodeType > &  types 
)

traverse node recursively and collect nodes of given types

Definition at line 205 of file visitor_utils.cpp.

◆ double_symbol()

SymbolType nmodl::double_symbol ( const std::string &  value,
PositionType pos 
)

Create a symbol for ast::Double AST class.

Parameters
valueDouble value parsed by lexer
posPosition of value in the mod file
Returns
Symbol for double value

Definition at line 28 of file nmodl_utils.cpp.

◆ get_external_functions()

std::vector< std::string > nmodl::get_external_functions ( )

Return functions that can be used in the NMODL.

Returns
vector of function names used in NMODL

Definition at line 308 of file token_mapping.cpp.

◆ get_external_variables()

std::vector< std::string > nmodl::get_external_variables ( )

Return variables declared in NEURON that are available to NMODL.

Returns
vector of NEURON variables

Definition at line 299 of file token_mapping.cpp.

◆ get_full_var_name()

std::string nmodl::get_full_var_name ( const ast::VarName node)

Given a VarName node, return the full var name including index.

Definition at line 274 of file visitor_utils.cpp.

◆ get_indexed_name()

std::string nmodl::get_indexed_name ( const ast::IndexedName node)

Given a Indexed node, return the name with index.

Definition at line 270 of file visitor_utils.cpp.

◆ integer_symbol()

SymbolType nmodl::integer_symbol ( int  value,
PositionType pos,
const char *  text 
)

Create a symbol for ast::Integer AST.

ast::Integer class also represent macro definition and hence could have associated text.

Parameters
valueInteger value parsed by lexer
posPosition of value in the mod file
textassociated macro for the value
Returns
Symbol for integer value

Definition at line 47 of file nmodl_utils.cpp.

◆ is_keyword()

bool nmodl::is_keyword ( const std::string &  name)

Check if given name is a keyword in NMODL.

Parameters
nametoken name
Returns
true if name is a keyword

Definition at line 264 of file token_mapping.cpp.

◆ is_method()

bool nmodl::is_method ( const std::string &  name)

Check if given name is an integration method in NMODL.

Parameters
nameName of the integration method
Returns
true if name is an integration method in NMODL

Definition at line 274 of file token_mapping.cpp.

◆ is_random_construct_function()

bool nmodl::is_random_construct_function ( const std::string &  name)

Is given name a one of the function for RANDOM construct.

Definition at line 285 of file visitor_utils.cpp.

◆ name_symbol()

SymbolType nmodl::name_symbol ( const std::string &  text,
PositionType pos,
TokenType  type 
)

Create symbol for ast::Name AST class.

Parameters
textText value parsed by lexer
posPosition of value in the mod file
typeToken type returned by lexer (see parser::NmodlParser::token::yytokentype)
Returns
Symbol for name value
Todo:
In addition to keywords and methods, there are also external definitions for math and neuron specific functions/variables. In the token we should mark those as external.

Definition at line 75 of file nmodl_utils.cpp.

◆ operator+()

ModToken nmodl::operator+ ( ModToken const &  adder1,
ModToken const &  adder2 
)

For example:

a at [118.9-14]
b at [121.4-5]

Output:

(a + b) at [118.9-121.5]

Definition at line 32 of file modtoken.cpp.

◆ operator<<()

std::ostream& nmodl::operator<< ( std::ostream &  stream,
const ModToken mt 
)

Overload ostream operator to print token in the form :

token at [line.start_column-end_column] type token

For example:

v at [118.9-14] type 376

Definition at line 26 of file modtoken.cpp.

◆ prime_symbol()

SymbolType nmodl::prime_symbol ( std::string  text,
PositionType pos 
)

Create symbol for ast::Prime AST class.

ast::Prime has name as well as order. Text returned by lexer has single quote (‘’`) as an order. We count the order and remove quote from the text.

Parameters
textPrime variable name parsed by lexer
posPosition of text in the mod file
Returns
Symbol for prime variable

Definition at line 93 of file nmodl_utils.cpp.

◆ sparse_solver_exists()

bool nmodl::sparse_solver_exists ( const ast::Ast node)

Definition at line 218 of file visitor_utils.cpp.

◆ statement_dependencies()

std::pair< std::string, std::unordered_set< std::string > > nmodl::statement_dependencies ( const std::shared_ptr< ast::Expression > &  lhs,
const std::shared_ptr< ast::Expression > &  rhs 
)

If lhs and rhs combined represent an assignment (we assume to have an "=" in between them) we extract the variables on which the assigned variable depends on.

We provide the input with lhs and rhs because there are a few nodes that have this similar structure but slightly different naming (binaryExpression, diff_eq_expression, linExpression)

Definition at line 246 of file visitor_utils.cpp.

◆ string_symbol()

SymbolType nmodl::string_symbol ( const std::string &  text,
PositionType pos 
)

Create symbol for ast::String AST class.

Parameters
textText value parsed by lexer
posPosition of value in the mod file
Returns
Symbol for string value

Definition at line 113 of file nmodl_utils.cpp.

◆ to_json()

std::string nmodl::to_json ( const ast::Ast node,
bool  compact,
bool  expand,
bool  add_nmodl 
)

Given AST node, return the JSON string representation.

Definition at line 235 of file visitor_utils.cpp.

◆ to_nmodl() [1/2]

std::string nmodl::to_nmodl ( const ast::Ast node,
const std::set< ast::AstNodeType > &  exclude_types 
)

Given AST node, return the NMODL string representation.

Definition at line 227 of file visitor_utils.cpp.

◆ to_nmodl() [2/2]

template<typename T >
std::enable_if<std::is_base_of<ast::Ast, T>::value, std::string>::type nmodl::to_nmodl ( const std::shared_ptr< T > &  node,
const std::set< ast::AstNodeType > &  exclude_types = {} 
)

Given a shared pointer to an AST node, return the NMODL string representation.

Definition at line 116 of file visitor_utils.hpp.

◆ token_symbol()

SymbolType nmodl::token_symbol ( const std::string &  key,
PositionType pos,
TokenType  type 
)

Create symbol for AST class.

These tokens doesn't have specific value to pass to the parser. They are more part of grammar. Depending on the type of toke, we create appropriate symbol. From lexer we pass token type (which is optional). This is required for reaction parsing where we have "lexical context". Hence, if token type is passed then we don't check/search for the token type.

Parameters
keyText parsed by lexer
posPosition of value in the mod file
typeToken type returned by lexer (see parser::NmodlParser::token::yytokentype)
Returns
Symbol for given token

if token type is not passed, check if it is keyword or method

we hit default case for missing token type. This is more likely a bug in the implementation where we forgot to handle token type.

Definition at line 135 of file nmodl_utils.cpp.

◆ token_type()

parser::NmodlParser::token_type nmodl::token_type ( const std::string &  name)

Return token type for given token name.

Parameters
nameToken name from lexer
Returns
type of NMODL token

Definition at line 284 of file token_mapping.cpp.

Variable Documentation

◆ logger

logger_type nmodl::logger = nmodl_logger.logger

Definition at line 34 of file logger.cpp.

◆ nmodl_logger

Logger nmodl::nmodl_logger("NMODL", "[%n] [%^%l%$] :: %v")