gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MathExpr Class Reference

#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

Nodeparse (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...
 
Noderoot
 Root node. More...
 

Detailed Description

Definition at line 48 of file mathexpr.hh.

Member Typedef Documentation

typedef double(* MathExpr::binOp)(double, double)
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.

Member Enumeration Documentation

enum MathExpr::Operator
private
Enumerator
bAdd 
bSub 
bMul 
bDiv 
bPow 
uNeg 
sValue 
sVariable 
nInvalid 

Definition at line 72 of file mathexpr.hh.

Constructor & Destructor Documentation

MathExpr::MathExpr ( std::string  expr)

Definition at line 49 of file mathexpr.cc.

References ArmISA::a, ArmISA::b, bAdd, bDiv, bMul, bPow, bSub, and uNeg.

Member Function Documentation

double MathExpr::eval ( EvalCallback  fn) const
inline

Evaluates the expression.

Parameters
fnA callback funcion to evaluate variables
Returns
The value for this expression

Definition at line 69 of file mathexpr.hh.

References eval(), and root.

Referenced by eval(), and MathExprPowerModel::tryEval().

double MathExpr::eval ( const Node n,
EvalCallback  fn 
) const
private
MathExpr::Node * MathExpr::parse ( std::string  expr)
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.

std::string MathExpr::toStr ( ) const
inline

Prints an ASCII representation of the expression tree.

Returns
A string containing the ASCII representation of the expression

Definition at line 60 of file mathexpr.hh.

References root, and toStr().

Referenced by MathExprPowerModel::eval(), and toStr().

std::string MathExpr::toStr ( Node n,
std::string  prefix 
) const
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().

Member Data Documentation

const int MathExpr::MAX_PRIO = 4
private

Definition at line 77 of file mathexpr.hh.

Referenced by parse().

std::array<OpSearch, uNeg + 1> MathExpr::ops
private

Operator list.

Definition at line 88 of file mathexpr.hh.

Referenced by eval(), and parse().

Node* MathExpr::root
private

Root node.

Definition at line 114 of file mathexpr.hh.

Referenced by eval(), and toStr().


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

Generated on Fri Jun 9 2017 13:04:14 for gem5 by doxygen 1.8.6