User Guide
|
Visitor for Units blocks of AST. More...
Visitor for Units blocks of AST.
This is simple example of visitor that uses base AstVisitor interface. We override AstVisitor::visit_program, AstVisitor::visit_unit_def and AstVisitor::visit_factor_def method. Furthermore it keeps the parser::UnitDriver to parse the units file and the strings generated by the units in the mod files.
Definition at line 42 of file units_visitor.hpp.
#include <units_visitor.hpp>
Private Attributes | |
parser::UnitDriver | units_driver |
Units Driver needed to parse the units file and the string produces by mod files' units. More... | |
std::string | units_dir |
Directory of units lib file that defines all the basic units. More... | |
const std::string | UNIT_FUZZ = "fuzz" |
Declaration of fuzz constant unit, which is the equivilant of 1 in mod files UNITS definitions. More... | |
|
default |
Default UnitsVisitor constructor.
|
inlineexplicit |
UnitsVisitor constructor that takes as argument the units file to parse the units from.
Definition at line 64 of file units_visitor.hpp.
|
inlinenoexcept |
Get the parser::UnitDriver to be able to use it outside the visitor::UnitsVisitor scope keeping the same units::UnitTable.
Definition at line 83 of file units_visitor.hpp.
|
overridevirtual |
Function to visit all the ast::FactorDef nodes and parse the units defined as ast::FactorDef in the UNITS block of mod files.
The new unit definition is based on a factor combined with units or other defined units. In the first case the factor saved to the ast::FactorDef node and printed to .cpp file is the one defined on the modfile. The factor and the dimensions saved to the units::UnitTable are based on the factor and the units defined in the modfile, so this factor will be calculated based on the base units of the units::UnitTable.
Example:
In the second case, the factor and the dimensions that are inserted to the units::UnitTable are based on the ast::FactorDef::unit1, like in MOD2C. However, the factor that is saved in the ast::FactorDef and printed in the .cpp file is the factor of the ast::FactorDef::unit1 divided by the factor of ast::FactorDef::unit2.
Example:
unit1
is mole k
and unit2 is mV-coulomb/degC
To parse the units defined in modfiles there are stringstreams created that are passed to the string parser, to be parsed by the unit parser used for parsing the nrnunits.lib
file, which takes care of all the units calculations.
.cpp file.
.cpp file the printed factor will be 9.64853090
but in the units::UnitTable the factor of FARADAY
will be 96485.30900000
Implements nmodl::visitor::Visitor.
Definition at line 83 of file units_visitor.cpp.
|
overridevirtual |
Override visit_program function to parse the nrnunits.lib
unit file before starting visiting the AST to parse the units defined in mod files.
Implements nmodl::visitor::Visitor.
Definition at line 22 of file units_visitor.cpp.
|
overridevirtual |
Function to visit all the ast::UnitDef nodes and parse the units defined as ast::UnitDef in the UNITS block of mod files.
units::Unit definition is based only on pre-defined units, parse only the new unit and the pre-defined units.
Example:
The ast::UnitDef is converted to a string that is able to be parsed by the unit parser which was used for parsing the nrnunits.lib
file. On nrnunits.lib
constant "1" is defined as "fuzz", so it must be converted.
Implements nmodl::visitor::Visitor.
Definition at line 38 of file units_visitor.cpp.
|
private |
Declaration of fuzz
constant unit, which is the equivilant of 1
in mod files UNITS definitions.
Definition at line 53 of file units_visitor.hpp.
|
private |
Directory of units lib file that defines all the basic units.
Definition at line 49 of file units_visitor.hpp.
|
private |
Units Driver needed to parse the units file and the string produces by mod files' units.
Definition at line 46 of file units_visitor.hpp.