gem5
v20.1.0.0
|
#include <mathexpr.hh>
Classes | |
class | Node |
struct | OpSearch |
Public Types | |
typedef std::function< double(std::string)> | EvalCallback |
Public Member Functions | |
MathExpr (std::string expr) | |
std::string | toStr () const |
Prints an ASCII representation of the expression tree. More... | |
double | eval (EvalCallback fn) const |
Evaluates the expression. More... | |
std::vector< std::string > | getVariables () const |
Return all variables in the this expression. More... | |
Private Types | |
enum | Operator { bAdd, bSub, bMul, bDiv, bPow, uNeg, sValue, sVariable, nInvalid } |
typedef double(* | binOp) (double, double) |
Private Member Functions | |
Node * | parse (std::string expr) |
Parse and create nodes from string. More... | |
std::string | toStr (Node *n, std::string prefix) const |
Print tree as string. More... | |
double | eval (const Node *n, EvalCallback fn) const |
Eval a node. More... | |
void | getVariables (const Node *n, std::vector< std::string > &vars) const |
Return all variable reachable from a node to a vector of strings. More... | |
Private Attributes | |
const int | MAX_PRIO = 4 |
std::array< OpSearch, uNeg+1 > | ops |
Operator list. More... | |
Node * | root |
Root node. More... | |
Definition at line 47 of file mathexpr.hh.
|
private |
Definition at line 93 of file mathexpr.hh.
typedef std::function<double(std::string)> MathExpr::EvalCallback |
Definition at line 52 of file mathexpr.hh.
|
private |
Enumerator | |
---|---|
bAdd | |
bSub | |
bMul | |
bDiv | |
bPow | |
uNeg | |
sValue | |
sVariable | |
nInvalid |
Definition at line 87 of file mathexpr.hh.
MathExpr::MathExpr | ( | std::string | expr | ) |
|
private |
Eval a node.
Definition at line 150 of file mathexpr.cc.
References eval(), ArmISA::fn, ArmISA::n, ops, panic, sValue, and sVariable.
|
inline |
Evaluates the expression.
fn | A callback funcion to evaluate variables |
Definition at line 68 of file mathexpr.hh.
References eval(), ArmISA::fn, and root.
Referenced by MathExprPowerModel::eval(), and eval().
|
inline |
Return all variables in the this expression.
This function starts from the root node and traverses all nodes while adding the variables it finds to a vector. Returns the found variables in a vector of strings
Definition at line 79 of file mathexpr.hh.
References root.
Referenced by getVariables().
|
private |
Return all variable reachable from a node to a vector of strings.
Definition at line 178 of file mathexpr.cc.
References getVariables(), ArmISA::n, nInvalid, sValue, and sVariable.
|
private |
Parse and create nodes from string.
This function parses a string expression into an expression tree.
It will look for operators in priority order to recursively build the tree, respecting parenthesization. Constants can be expressed in any format accepted by std::stod, whereas variables are essentially [A-Za-z0-9.$\]+
Definition at line 75 of file mathexpr.cc.
References ArmISA::c, ArmISA::i, MipsISA::l, MAX_PRIO, ArmISA::n, ops, MipsISA::p, MipsISA::r, sValue, sVariable, and ArmISA::v.
|
inline |
Prints an ASCII representation of the expression tree.
Definition at line 59 of file mathexpr.hh.
Referenced by toStr().
|
private |
Print tree as string.
Definition at line 167 of file mathexpr.cc.
|
private |
Definition at line 92 of file mathexpr.hh.
Referenced by parse().
|
private |
Root node.
Definition at line 129 of file mathexpr.hh.
Referenced by eval(), getVariables(), and toStr().