The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::statistics::expression::Expression Class Reference

Expression container/builder. Contains a single ExpressionNode representing the root of an expression tree. This is the object on which the parser operates to build an expression incrementally through basic operators. More...

#include <Expression.hpp>

Public Member Functions

 Expression ()=default
 Constructs an expression containing no content.
 
 Expression (const Expression &rhp)
 Copy Constructor.
 
 Expression (Expression &&rhp)
 Move Constructor.
 
 Expression (const std::string &expression, TreeNode *context)
 Construct with string expression.
 
 Expression (const std::string &expression, TreeNode *context, const StatisticPairs &report_si)
 Construct with string expression.
 
 Expression (const std::string &expression, TreeNode *context, std::vector< const TreeNode * > &already_used)
 Construct with string expression.
 
 Expression (ExpressionNode *item)
 Blind content constructor.
 
 Expression (double d)
 Constant construction.
 
 Expression (operation_t type, ExpressionNode *op1, ExpressionNode *op2=nullptr, ExpressionNode *op3=nullptr)
 Operation construction.
 
 Expression (const TreeNode *n, std::vector< const TreeNode * > &used)
 Stat/Counter/Parameter construction.
 
template<typename RetT , typename ArgT >
 Expression (const std::string &name, RetT(*fxn)(ArgT), const Expression &a)
 Unary function construction.
 
template<typename RetT , typename ArgT >
 Expression (const std::string &name, std::function< RetT(ArgT)> &, const Expression &a)
 Unary function construction.
 
template<typename RetT , typename ArgT >
 Expression (const std::string &name, RetT(*fxn)(ArgT, ArgT), const Expression &a, const Expression &b)
 Binary function construction.
 
template<typename RetT >
 Expression (const std::string &name, const RetT &functor, const Expression &a, const Expression &b)
 Binary function construction.
 
template<typename RetT , typename ArgT >
 Expression (const std::string &name, RetT(*fxn)(ArgT, ArgT, ArgT), const Expression &a, const Expression &b, const Expression &c)
 Ternary function construction.
 
virtual ~Expression ()
 Virtual destructor.
 
Expressionoperator= (const Expression &rhp)
 Assignment operator. Clones the content of rhp and discards current expression content.
 
Expressionoperator= (Expression &&rhp)
 Assignment operator with move. Moves content of rhp and discards current expression content.
 
ExpressionNodecloneContent () const
 Makes a clone of the content of this expression.
 
uint32_t getStats (std::vector< const StatisticInstance * > &results) const
 Gets the statistics present in this expression.
 
bool hasContent () const
 Does this expression have content.
 
template<typename RetT , typename ArgT >
Expression ufunc (const std::string &name, RetT(*fxn)(ArgT), const Expression &a) const
 Construct a unary function having the given name and function.
 
template<typename RetT , typename ArgT >
Expression ufunc (const std::string &name, std::function< RetT(ArgT)> &, const Expression &a) const
 Construct a unary function having the given name and functor.
 
template<typename RetT , typename ArgT >
Expression bfunc (const std::string &name, RetT(*fxn)(ArgT, ArgT), const Expression &a, const Expression &b) const
 Construct a binary function having the given name and function.
 
template<typename RetT >
Expression bfunc (const std::string &name, const RetT &functor, const Expression &a, const Expression &b) const
 Construct a binary function having the given name and functor.
 
template<typename RetT , typename ArgT >
Expression tfunc (const std::string &name, RetT(*fxn)(ArgT, ArgT, ArgT), const Expression &a, const Expression &b, const Expression &c) const
 Construct a ternary function having the given name and function.
 
Expressionoperator= (double d)
 Construct a constant node.
 
Expression operator+ () const
 Return this expression with no effect.
 
Expression operator- () const
 Return this expression with a negation inserted.
 
Expression operator+ (const Expression &rhp) const
 Return a new expression of: *this + rhp.
 
Expression operator- (const Expression &rhp) const
 Return a new expression of: *this - rhp.
 
Expression operator* (const Expression &rhp) const
 Return a new expression of: *this * rhp.
 
Expression operator/ (const Expression &rhp) const
 Return a new expression of: *this / rhp.
 
Expressionoperator+= (const Expression &rhp)
 Return this expression with a node adding rhp.
 
Expressionoperator-= (const Expression &rhp)
 Return this expression with a node subtracting rhp.
 
Expressionoperator*= (const Expression &rhp)
 Return this expression with a node multiplying by rhp.
 
Expressionoperator/= (const Expression &rhp)
 Return this expression with a node dividing by rhp.
 
double evaluate () const
 Compute value of this operate in simulation for the current computation window.
 
void start ()
 Notify every item in this expression to start a new computation window.
 
void end ()
 Notify every item in this expression to end the current computation window.
 
void dump (std::ostream &o, bool show_range=true, bool resolve_subexprs=true) const
 Write the content of this entire expression to an ostream.
 
bool supportsCompression () const
 
std::string stringize (bool show_range=true, bool resolve_subexprs=true) const
 Return a string representing this expression including any TreeNode dependencies.
 
const ClockgetClock ()
 Gets the clock associated with the content of this expression. This is done by finding all TreeNodes on which the Expression depends.
 
void getClocks (std::vector< const Clock * > &clocks) const
 Gets all clocks associated with this Expression.
 

Detailed Description

Expression container/builder. Contains a single ExpressionNode representing the root of an expression tree. This is the object on which the parser operates to build an expression incrementally through basic operators.

Note
Any TreeNodes referenced by an expression should outlast it. It is not safe to evaluate or even print the expression if any its references are destructed because they will leave dangling pointers.

Expressions have an inherit computation window built in (like StatisticDef). This means that when the expression is created, any counter or stat-def referenced is treated as if it was 0 at that point. When the expression is later evaluated, the delta for those counters or stat-defs is used. This can be avoided simply by evaluating with evaluateAbsolute (generally not recommended)

If expressions created during different simulation states are joined together, then they may see different windows. This is intentional so that comparisons can be made between different simulation time windows in a single expression (most users will not need to do this). This issue can be avoided by manually calling start()

Definition at line 67 of file Expression.hpp.

Constructor & Destructor Documentation

◆ Expression() [1/14]

sparta::statistics::expression::Expression::Expression ( const Expression rhp)
inline

Copy Constructor.

Definition at line 86 of file Expression.hpp.

◆ Expression() [2/14]

sparta::statistics::expression::Expression::Expression ( Expression &&  rhp)
inline

Move Constructor.

Definition at line 98 of file Expression.hpp.

◆ Expression() [3/14]

sparta::statistics::expression::Expression::Expression ( const std::string &  expression,
TreeNode context 
)

Construct with string expression.

Parameters
exprString containing an arithmetic expression
contextTreeNode from which variables in the expression will be searched for. Must not be nullptr

◆ Expression() [4/14]

sparta::statistics::expression::Expression::Expression ( const std::string &  expression,
TreeNode context,
const StatisticPairs report_si 
)

Construct with string expression.

Parameters
exprString containing an arithmetic expression
contextTreeNode from which variables in the expression
report_siPreviously defined StatisticInstances in the report

◆ Expression() [5/14]

sparta::statistics::expression::Expression::Expression ( const std::string &  expression,
TreeNode context,
std::vector< const TreeNode * > &  already_used 
)

Construct with string expression.

Parameters
exprString containing an arithmetic expression
contextOptional TreeNode from which variables in the expression will be searched for. Must not be nullptr
already_usedTreeNodes already in an expression containing this expression

◆ Expression() [6/14]

sparta::statistics::expression::Expression::Expression ( ExpressionNode item)
inline

Blind content constructor.

Parameters
itemExpression item to contain. Takes ownership

Definition at line 139 of file Expression.hpp.

◆ Expression() [7/14]

sparta::statistics::expression::Expression::Expression ( double  d)
inline

Constant construction.

Definition at line 572 of file Expression.hpp.

◆ Expression() [8/14]

sparta::statistics::expression::Expression::Expression ( operation_t  type,
ExpressionNode op1,
ExpressionNode op2 = nullptr,
ExpressionNode op3 = nullptr 
)
inline

Operation construction.

Definition at line 578 of file Expression.hpp.

◆ Expression() [9/14]

sparta::statistics::expression::Expression::Expression ( const TreeNode n,
std::vector< const TreeNode * > &  used 
)

Stat/Counter/Parameter construction.

Parameters
[in]nNode to use (StatisticDef, Parameter, or Counter variant)
[in]usedVector of nodes already used higher up in an enclosing expression (for preventing cycles). Use a dummy object if there is no chance of cyclic expressions

◆ Expression() [10/14]

template<typename RetT , typename ArgT >
sparta::statistics::expression::Expression::Expression ( const std::string &  name,
RetT(*)(ArgT)  fxn,
const Expression a 
)
inline

Unary function construction.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.

Definition at line 588 of file Expression.hpp.

Here is the call graph for this function:

◆ Expression() [11/14]

template<typename RetT , typename ArgT >
sparta::statistics::expression::Expression::Expression ( const std::string &  name,
std::function< RetT(ArgT)> &  fxn,
const Expression a 
)
inline

Unary function construction.

Template Parameters
RetTReturn type of functor. Must be convertable to double
ArgTArgument type of functor.

Definition at line 597 of file Expression.hpp.

Here is the call graph for this function:

◆ Expression() [12/14]

template<typename RetT , typename ArgT >
sparta::statistics::expression::Expression::Expression ( const std::string &  name,
RetT(*)(ArgT, ArgT)  fxn,
const Expression a,
const Expression b 
)
inline

Binary function construction.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.

Definition at line 606 of file Expression.hpp.

Here is the call graph for this function:

◆ Expression() [13/14]

template<typename RetT >
sparta::statistics::expression::Expression::Expression ( const std::string &  name,
const RetT &  functor,
const Expression a,
const Expression b 
)
inline

Binary function construction.

Template Parameters
RetTReturn type of functor. Must be convertable to double
ArgTArgument type of functor.

Definition at line 616 of file Expression.hpp.

Here is the call graph for this function:

◆ Expression() [14/14]

template<typename RetT , typename ArgT >
sparta::statistics::expression::Expression::Expression ( const std::string &  name,
RetT(*)(ArgT, ArgT, ArgT)  fxn,
const Expression a,
const Expression b,
const Expression c 
)
inline

Ternary function construction.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.

Definition at line 624 of file Expression.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ bfunc() [1/2]

template<typename RetT >
Expression sparta::statistics::expression::Expression::bfunc ( const std::string &  name,
const RetT &  functor,
const Expression a,
const Expression b 
) const
inline

Construct a binary function having the given name and functor.

Template Parameters
RetTReturn type of functor. Must be convertable to double
ArgTArgument type of functor.
Parameters
nameName of the function (e.g. fabs)
fxnFunctor to invoke to compute the value. Must not be null
aOperand 1 of the binary function
bOperand 2 of the binary function

Definition at line 664 of file Expression.hpp.

Here is the call graph for this function:

◆ bfunc() [2/2]

template<typename RetT , typename ArgT >
Expression sparta::statistics::expression::Expression::bfunc ( const std::string &  name,
RetT(*)(ArgT, ArgT)  fxn,
const Expression a,
const Expression b 
) const
inline

Construct a binary function having the given name and function.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.
Parameters
nameName of the function (e.g. fabs)
fxnFunction pointer to invoke to compute the value. Must not be nullptr
aOperand 1 of the binary function
bOperand 2 of the binary function

Definition at line 654 of file Expression.hpp.

Here is the call graph for this function:

◆ cloneContent()

ExpressionNode * sparta::statistics::expression::Expression::cloneContent ( ) const
inline

Makes a clone of the content of this expression.

Exceptions
SpartaExceptionif this node has null content

Definition at line 266 of file Expression.hpp.

◆ dump()

void sparta::statistics::expression::Expression::dump ( std::ostream &  o,
bool  show_range = true,
bool  resolve_subexprs = true 
) const
inline

Write the content of this entire expression to an ostream.

Note
Does not evaluate the expression
Parameters
oOstream to write to
show_rangeShould the range be shown in any subexpression nodes.
resolve_subexprsShould any referenced statistic defs be expanded to their full expressions so that this becomes an expression containing only counters.

Definition at line 482 of file Expression.hpp.

◆ end()

void sparta::statistics::expression::Expression::end ( )
inline

Notify every item in this expression to end the current computation window.

Note
Has no effect if this expression has no content
See also
sparta::StatisticInstance
hasContent

Definition at line 466 of file Expression.hpp.

◆ evaluate()

double sparta::statistics::expression::Expression::evaluate ( ) const
inline

Compute value of this operate in simulation for the current computation window.

Definition at line 437 of file Expression.hpp.

◆ getClock()

const Clock * sparta::statistics::expression::Expression::getClock ( )
inline

Gets the clock associated with the content of this expression. This is done by finding all TreeNodes on which the Expression depends.

Returns
The clock if at least one TreeNode is found in this expression and all found TreeNodes have the same clock. Returns nullptr if this Expression contains no TreeNodes or none of those nodes have associated Clocks.

Definition at line 523 of file Expression.hpp.

Here is the call graph for this function:

◆ getClocks()

void sparta::statistics::expression::Expression::getClocks ( std::vector< const Clock * > &  clocks) const
inline

Gets all clocks associated with this Expression.

Parameters
clocksVector of clocks to which all clocks contained in this Expression will be added. Does not clear this vector.

Definition at line 545 of file Expression.hpp.

◆ getStats()

uint32_t sparta::statistics::expression::Expression::getStats ( std::vector< const StatisticInstance * > &  results) const
inline

Gets the statistics present in this expression.

Returns
Number of stats added to results
Parameters
resultsVector of pointers to StatisticInstances. All statistics within this class will be appended to the results vector. These pointers are valid until this expression is modified or deleted

Definition at line 280 of file Expression.hpp.

◆ hasContent()

bool sparta::statistics::expression::Expression::hasContent ( ) const
inline

Does this expression have content.

Note
This does not necessarily imply that the expression will be successfully evaluated

Definition at line 289 of file Expression.hpp.

◆ operator*()

Expression sparta::statistics::expression::Expression::operator* ( const Expression rhp) const
inline

Return a new expression of: *this * rhp.

Definition at line 725 of file Expression.hpp.

Here is the call graph for this function:

◆ operator*=()

Expression & sparta::statistics::expression::Expression::operator*= ( const Expression rhp)
inline

Return this expression with a node multiplying by rhp.

Definition at line 768 of file Expression.hpp.

Here is the call graph for this function:

◆ operator+() [1/2]

Expression sparta::statistics::expression::Expression::operator+ ( ) const
inline

Return this expression with no effect.

Definition at line 689 of file Expression.hpp.

Here is the call graph for this function:

◆ operator+() [2/2]

Expression sparta::statistics::expression::Expression::operator+ ( const Expression rhp) const
inline

Return a new expression of: *this + rhp.

Definition at line 705 of file Expression.hpp.

Here is the call graph for this function:

◆ operator+=()

Expression & sparta::statistics::expression::Expression::operator+= ( const Expression rhp)
inline

Return this expression with a node adding rhp.

Definition at line 745 of file Expression.hpp.

Here is the call graph for this function:

◆ operator-() [1/2]

Expression sparta::statistics::expression::Expression::operator- ( ) const
inline

Return this expression with a negation inserted.

Definition at line 697 of file Expression.hpp.

Here is the call graph for this function:

◆ operator-() [2/2]

Expression sparta::statistics::expression::Expression::operator- ( const Expression rhp) const
inline

Return a new expression of: *this - rhp.

Definition at line 715 of file Expression.hpp.

Here is the call graph for this function:

◆ operator-=()

Expression & sparta::statistics::expression::Expression::operator-= ( const Expression rhp)
inline

Return this expression with a node subtracting rhp.

Definition at line 756 of file Expression.hpp.

Here is the call graph for this function:

◆ operator/()

Expression sparta::statistics::expression::Expression::operator/ ( const Expression rhp) const
inline

Return a new expression of: *this / rhp.

Definition at line 735 of file Expression.hpp.

Here is the call graph for this function:

◆ operator/=()

Expression & sparta::statistics::expression::Expression::operator/= ( const Expression rhp)
inline

Return this expression with a node dividing by rhp.

Definition at line 779 of file Expression.hpp.

Here is the call graph for this function:

◆ operator=() [1/3]

Expression & sparta::statistics::expression::Expression::operator= ( const Expression rhp)
inline

Assignment operator. Clones the content of rhp and discards current expression content.

Parameters
rhpExpression to copy content from

Definition at line 238 of file Expression.hpp.

◆ operator=() [2/3]

Expression & sparta::statistics::expression::Expression::operator= ( double  d)
inline

Construct a constant node.

Note
that this is a non-const operation
Returns
*this

Definition at line 682 of file Expression.hpp.

◆ operator=() [3/3]

Expression & sparta::statistics::expression::Expression::operator= ( Expression &&  rhp)
inline

Assignment operator with move. Moves content of rhp and discards current expression content.

Parameters
rhpExpression to move content from

Definition at line 254 of file Expression.hpp.

◆ start()

void sparta::statistics::expression::Expression::start ( )
inline

Notify every item in this expression to start a new computation window.

Note
Has no effect if this expression has no content
See also
sparta::StatisticInstance
hasContent

Definition at line 453 of file Expression.hpp.

◆ stringize()

std::string sparta::statistics::expression::Expression::stringize ( bool  show_range = true,
bool  resolve_subexprs = true 
) const
inline

Return a string representing this expression including any TreeNode dependencies.

Warning
It is not safe to call this if the expression depends on any destructed TreeNodes.
Parameters
show_rangeSee dump
resolve_subexprsSee dump
Returns
String representation of this expression

Definition at line 508 of file Expression.hpp.

Here is the call graph for this function:

◆ supportsCompression()

bool sparta::statistics::expression::Expression::supportsCompression ( ) const
inline

Definition at line 492 of file Expression.hpp.

◆ tfunc()

template<typename RetT , typename ArgT >
Expression sparta::statistics::expression::Expression::tfunc ( const std::string &  name,
RetT(*)(ArgT, ArgT, ArgT)  fxn,
const Expression a,
const Expression b,
const Expression c 
) const
inline

Construct a ternary function having the given name and function.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.
Parameters
nameName of the function (e.g. fabs)
fxnFunction pointer to invoke to compute the value. Must not be nullptr
aOperand 1 of the binary function
bOperand 2 of the binary function
cOperand 3 of the binary function

Definition at line 672 of file Expression.hpp.

Here is the call graph for this function:

◆ ufunc() [1/2]

template<typename RetT , typename ArgT >
Expression sparta::statistics::expression::Expression::ufunc ( const std::string &  name,
RetT(*)(ArgT)  fxn,
const Expression a 
) const
inline

Construct a unary function having the given name and function.

Template Parameters
RetTReturn type of function pointer. Must be convertable to double
ArgTArgument type of function pointer.
Parameters
nameName of the function (e.g. fabs)
fxnFunction pointer to invoke to compute the value. Must not be nullptr
aOperand of the unary function

Definition at line 635 of file Expression.hpp.

Here is the call graph for this function:

◆ ufunc() [2/2]

template<typename RetT , typename ArgT >
Expression sparta::statistics::expression::Expression::ufunc ( const std::string &  name,
std::function< RetT(ArgT)> &  fxn,
const Expression a 
) const
inline

Construct a unary function having the given name and functor.

Template Parameters
RetTReturn type of functor. Must be convertable to double
ArgTArgument type of functor.
Parameters
nameName of the function (e.g. fabs)
fxnFunctor to invoke to compute the value. Must not be null
aOperand of the unary function

Definition at line 645 of file Expression.hpp.

Here is the call graph for this function:

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