gem5
|
#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... | |
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... | |
Private Attributes | |
const int | MAX_PRIO = 4 |
std::array< OpSearch, uNeg+1 > | ops |
Operator list. More... | |
Node * | root |
Root node. More... | |
Definition at line 48 of file mathexpr.hh.
|
private |
Definition at line 78 of file mathexpr.hh.
typedef std::function<double(std::string)> MathExpr::EvalCallback |
Definition at line 53 of file mathexpr.hh.
|
private |
Enumerator | |
---|---|
bAdd | |
bSub | |
bMul | |
bDiv | |
bPow | |
uNeg | |
sValue | |
sVariable | |
nInvalid |
Definition at line 72 of file mathexpr.hh.
MathExpr::MathExpr | ( | std::string | expr | ) |
|
inline |
Evaluates the expression.
fn | A callback funcion to evaluate variables |
Definition at line 69 of file mathexpr.hh.
Referenced by eval(), and MathExprPowerModel::tryEval().
|
private |
Eval a node.
Definition at line 152 of file mathexpr.cc.
References eval(), ArmISA::fn, MathExpr::Node::l, MathExpr::Node::op, ops, panic, MathExpr::Node::r, sValue, sVariable, MathExpr::Node::value, and MathExpr::Node::variable.
|
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 77 of file mathexpr.cc.
References ArmISA::c, ArmISA::i, MathExpr::Node::l, MipsISA::l, MAX_PRIO, ArmISA::n, MathExpr::Node::op, ops, MipsISA::p, MipsISA::r, MathExpr::Node::r, sValue, sVariable, ArmISA::v, MathExpr::Node::value, and MathExpr::Node::variable.
|
inline |
Prints an ASCII representation of the expression tree.
Definition at line 60 of file mathexpr.hh.
Referenced by MathExprPowerModel::eval(), and toStr().
|
private |
Print tree as string.
Definition at line 169 of file mathexpr.cc.
References MathExpr::Node::l, MathExpr::Node::r, toStr(), and MathExpr::Node::toStr().
|
private |
Definition at line 77 of file mathexpr.hh.
Referenced by parse().
|
private |