SeExpr

Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
SeExpr2::Expression Class Reference

main expression class More...

`#include <Expression.h>`

Inheritance diagram for SeExpr2::Expression:

## Classes
struct | Error
| Represents a parse or type checking error in an expression. More...

## Public Types
enum | EvaluationStrategy { UseInterpreter, UseLLVM }
| Types of evaluation strategies that are available. More...

## Public Member Functions
| Expression (EvaluationStrategy be=Expression::defaultEvaluationStrategy)
| Expression (const std::string &e, const ExprType &type=ExprType().FP(3), EvaluationStrategy be=Expression::defaultEvaluationStrategy, const Context &context=Context::global())
virtual | ~Expression ()
void | setDesiredReturnType (const ExprType &type)
void | setExpr (const std::string &e)
const std::string & | getExpr () const
| Get the string that this expression is currently set to evaluate. More...
bool | syntaxOK () const
bool | isValid () const
const std::string & | parseError () const
const std::vector< Error > & | getErrors () const
const std::vector< std::pair< int, int > > & | getComments () const
bool | isConstant () const
bool | usesVar (const std::string &name) const
bool | usesFunc (const std::string &name) const
bool | isThreadSafe () const
void | setThreadUnsafe (const std::string &functionName) const
const std::vector< std::string > & | getThreadUnsafeFunctionCalls () const
bool | wantVec () const
bool | isVec () const
const ExprType & | returnType () const
void | evalMultiple (VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd) const
| Evaluate multiple blocks. More...
const double * | evalFP (VarBlock *varBlock=nullptr) const
const char * | evalStr (VarBlock *varBlock=nullptr) const
void | reset ()
virtual ExprVarRef * | resolveVar (const std::string &name) const
virtual ExprFunc * | resolveFunc (const std::string &name) const
void | addError (const std::string &error, const int startPos, const int endPos) const
void | addComment (int pos, int length)
const Context & | context () const
void | setContext (const Context &context)
void | debugPrintParseTree () const
void | debugPrintInterpreter () const
void | debugPrintLLVM () const
void | setVarBlockCreator (const VarBlockCreator *varBlockCreator)
const VarBlockCreator * | varBlockCreator () const
void | addVar (const char *n) const
| add local variable (this is for internal use) More...
void | addFunc (const char *n) const
| add function evaluation (this is for internal use) More...

## Static Public Attributes
static EvaluationStrategy | defaultEvaluationStrategy = chooseDefaultEvaluationStrategy()
| What evaluation strategy to use by default. More...
static bool | debugging = getenv("SE_EXPR_DEBUG") != 0
| Whether to debug expressions. More...

## Protected Member Functions
void | prepIfNeeded () const

## Protected Attributes
ExprType | _desiredReturnType
ExprVarEnvBuilder | _envBuilder
ExprNode * | _parseTree

## Private Member Functions
| Expression (const Expression &e)
Expression & | operator= (const Expression &e)
void | parse () const
void | parseIfNeeded () const
void | prep () const

## Private Attributes
bool | _wantVec
ExprType | _returnType
std::string | _expression
EvaluationStrategy | _evaluationStrategy
const Context * | _context
bool | _isValid
bool | _parsed
bool | _prepped
std::string | _parseError
std::vector< Error > | _errors
std::vector< std::pair< int, int > > | _comments
std::set< std::string > | _vars
std::set< std::string > | _funcs
std::vector< std::string > | _threadUnsafeFunctionCalls
Interpreter * | _interpreter
int | _returnSlot
LLVMEvaluator * | _llvmEvaluator
const VarBlockCreator * | _varBlockCreator = 0

## Detailed Description

main expression class

Definition at line 76 of file Expression.h.

## Member Enumeration Documentation

## ◆ EvaluationStrategy

enum SeExpr2::Expression::EvaluationStrategy

Types of evaluation strategies that are available.

Enumerator
UseInterpreter |
UseLLVM |

Definition at line 79 of file Expression.h.

## Constructor & Destructor Documentation

## ◆ Expression() [1/3]

Expression::Expression | ( | Expression::EvaluationStrategy | evaluationStrategy = `Expression::defaultEvaluationStrategy` | ) |

Definition at line 90 of file Expression.cpp.

References SeExpr2::ExprFunc::init().

## ◆ Expression() [2/3]

Expression::Expression | ( | const std::string & | e,
|  | const ExprType & | type = `ExprType().FP(3)`,
|  | EvaluationStrategy | be = `Expression::defaultEvaluationStrategy`,
|  | const Context & | context = `Context::global()`
| ) |  |

Definition at line 97 of file Expression.cpp.

References SeExpr2::ExprFunc::init().

## ◆ ~Expression()

Expression::~Expression | ( |  | ) |
| virtual

Definition at line 107 of file Expression.cpp.

References _llvmEvaluator, and reset().

## ◆ Expression() [3/3]

SeExpr2::Expression::Expression | ( | const Expression & | e | ) |
| private

No definition by design.

## Member Function Documentation

## ◆ addComment()

void SeExpr2::Expression::addComment | ( | int | pos,
|  | int | length
| ) |  |
| inline

records a comment

Definition at line 210 of file Expression.h.

References _comments, and SeExpr2::length().

## ◆ addError()

void SeExpr2::Expression::addError | ( | const std::string & | error,
|  | const int | startPos,
|  | const int | endPos
| ) |  | const
| inline

records an error in prep or parse stage

Definition at line 205 of file Expression.h.

References _errors.

Referenced by SeExpr2::ExprNode::addError(), parse(), and SeExpr2::DExpression::resolveVar().

## ◆ addFunc()

void SeExpr2::Expression::addFunc | ( | const char * | n | ) | const
| inline

add function evaluation (this is for internal use)

Definition at line 321 of file Expression.h.

References _funcs.

Referenced by SeExpr2::ExprFuncNode::ExprFuncNode().

## ◆ addVar()

void SeExpr2::Expression::addVar | ( | const char * | n | ) | const
| inline

add local variable (this is for internal use)

Definition at line 318 of file Expression.h.

References _vars.

Referenced by SeExpr2::ExprVarNode::prep().

## ◆ context()

const Context& SeExpr2::Expression::context | ( |  | ) | const
| inline

Returns a read only map of local variables that were set An immutable reference to access context parameters from say ExprFuncX's

Definition at line 216 of file Expression.h.

References _context.

Referenced by SeExpr2::DExpression::DExpression(), and setContext().

## ◆ debugPrintInterpreter()

void Expression::debugPrintInterpreter | ( |  | ) | const

Debug printout of interpreter evaluation program

Definition at line 112 of file Expression.cpp.

References _interpreter, _returnSlot, and SeExpr2::Interpreter::print().

## ◆ debugPrintLLVM()

void Expression::debugPrintLLVM | ( |  | ) | const

Debug printout of LLVM evaluation

Definition at line 119 of file Expression.cpp.

References _llvmEvaluator, and SeExpr2::LLVMEvaluator::debugPrint().

## ◆ debugPrintParseTree()

void Expression::debugPrintParseTree | ( |  | ) | const

Debug printout of parse tree

Definition at line 121 of file Expression.cpp.

References _desiredReturnType, _parseTree, SeExpr2::ExprType::toString(), SeExpr2::ExprNode::type(), and SeExpr2::Walker< constnode >::walk().

Referenced by prep().

## ◆ evalFP()

const double * Expression::evalFP | ( | VarBlock * | varBlock = `nullptr` | ) | const

Evaluates and returns float (check returnType()!)

Definition at line 304 of file Expression.cpp.

References _evaluationStrategy, _interpreter, _isValid, _llvmEvaluator, _returnSlot, SeExpr2::Interpreter::d, SeExpr2::VarBlock::d, SeExpr2::Interpreter::eval(), SeExpr2::LLVMEvaluator::evalFP(), prepIfNeeded(), SeExpr2::VarBlock::threadSafe, and UseInterpreter.

Referenced by SeExpr2::DExpression::eval(), evalMultiple(), and ExprGrapherView::update().

## ◆ evalMultiple()

void Expression::evalMultiple | ( | VarBlock * | varBlock,
|  | int | outputVarBlockOffset,
|  | size_t | rangeStart,
|  | size_t | rangeEnd
| ) |  | const

Evaluate multiple blocks.

Definition at line 318 of file Expression.cpp.

References _desiredReturnType, _evaluationStrategy, _isValid, _llvmEvaluator, SeExpr2::VarBlock::data(), SeExpr2::ExprType::dim(), evalFP(), SeExpr2::LLVMEvaluator::evalMultiple(), f(), SeExpr2::VarBlock::indirectIndex, prepIfNeeded(), and UseInterpreter.

## ◆ evalStr()

const char * Expression::evalStr | ( | VarBlock * | varBlock = `nullptr` | ) | const

Evaluates and returns string (check returnType()!)

Definition at line 339 of file Expression.cpp.

References _evaluationStrategy, _interpreter, _isValid, _llvmEvaluator, _returnSlot, SeExpr2::Interpreter::eval(), SeExpr2::LLVMEvaluator::evalStr(), prepIfNeeded(), SeExpr2::Interpreter::s, SeExpr2::VarBlock::s, SeExpr2::VarBlock::threadSafe, and UseInterpreter.

Referenced by SeExpr2::DExpression::eval().

## ◆ getComments()

const std::vector<std::pair<int, int> >& SeExpr2::Expression::getComments | ( |  | ) | const
| inline

Get a reference to a list of the ranges where comments occurred

Definition at line 147 of file Expression.h.

References _comments.

## ◆ getErrors()

const std::vector<Error>& SeExpr2::Expression::getErrors | ( |  | ) | const
| inline

Get a reference to a list of parse errors in the expression. The error structure gives location information as well as the errors itself.

Definition at line 144 of file Expression.h.

References _errors.

Referenced by ExprDialog::applyExpression().

## ◆ getExpr()

const std::string& SeExpr2::Expression::getExpr | ( |  | ) | const
| inline

Get the string that this expression is currently set to evaluate.

Definition at line 122 of file Expression.h.

References _expression.

Referenced by SeExpr2::ExprNode::toString().

## ◆ getThreadUnsafeFunctionCalls()

const std::vector<std::string>& SeExpr2::Expression::getThreadUnsafeFunctionCalls | ( |  | ) | const
| inline

Returns a list of functions that are not threadSafe

Definition at line 169 of file Expression.h.

References _threadUnsafeFunctionCalls.

## ◆ isConstant()

bool Expression::isConstant | ( |  | ) | const

Check if expression is constant. Expr will be parsed if needed. No binding is required.

Definition at line 179 of file Expression.cpp.

References SeExpr2::ExprType::isLifetimeConstant(), parseIfNeeded(), and returnType().

## ◆ isThreadSafe()

bool SeExpr2::Expression::isThreadSafe | ( |  | ) | const
| inline

Returns whether the expression contains and calls to non-threadsafe

Definition at line 162 of file Expression.h.

References _threadUnsafeFunctionCalls.

## ◆ isValid()

bool SeExpr2::Expression::isValid | ( |  | ) | const
| inline

Check if expression is valid. Expr will be parsed if needed. Variables and functions will also be bound. If this returns false, the error message can be accessed via parseError()

Definition at line 133 of file Expression.h.

References _isValid, and prepIfNeeded().

Referenced by ExprDialog::applyExpression(), prep(), ExprGrapherView::update(), ExprDialog::verifiedAccept(), and ExprDialog::verifiedApply().

## ◆ isVec()

bool Expression::isVec | ( |  | ) | const

Determine if expression computes a vector (may be false even if wantVec is true). Expr will be parsed and variables and functions will be bound if needed.

Definition at line 294 of file Expression.cpp.

References _isValid, _parseTree, _wantVec, SeExpr2::ExprNode::isVec(), and prepIfNeeded().

## ◆ operator=()

Expression& SeExpr2::Expression::operator= | ( | const Expression & | e | ) |
| private

## ◆ parse()

void Expression::parse | ( |  | ) | const
| private

Parse, and remember parse error if any

Definition at line 194 of file Expression.cpp.

References _comments, _expression, _parsed, _parseError, _parseTree, _wantVec, addError(), and SeExpr2::ExprParse().

Referenced by parseIfNeeded().

## ◆ parseError()

const std::string& SeExpr2::Expression::parseError | ( |  | ) | const
| inline

Get parse error (if any). First call syntaxOK or isValid to parse (and optionally bind) the expression.

Definition at line 140 of file Expression.h.

References _parseError.

Referenced by prep().

## ◆ parseIfNeeded()

void SeExpr2::Expression::parseIfNeeded | ( |  | ) | const
| inline private

Parse, but only if not yet parsed

Definition at line 242 of file Expression.h.

References _parsed, and parse().

Referenced by isConstant(), prep(), syntaxOK(), usesFunc(), and usesVar().

## ◆ prep()

void Expression::prep | ( |  | ) | const
| private

Prepare expression (bind vars/functions, etc.) and remember error if any

Definition at line 204 of file Expression.cpp.

References _desiredReturnType, _envBuilder, _errors, _evaluationStrategy, _expression, _interpreter, _isValid, _llvmEvaluator, _parseError, _parseTree, _prepped, _returnSlot, _returnType, SeExpr2::ExprNode::addError(), SeExpr2::Interpreter::addOp(), SeExpr2::Interpreter::addOperand(), SeExpr2::Interpreter::allocFP(), SeExpr2::ExprNode::buildInterpreter(), debugging, debugPrintParseTree(), SeExpr2::ExprType::dim(), SeExpr2::Interpreter::endOp(), SeExpr2::ExprType::Error(), SeExpr2::ExprType::isFP(), isValid(), p, parseError(), parseIfNeeded(), SeExpr2::ExprNode::prep(), SeExpr2::LLVMEvaluator::prepLLVM(), SeExpr2::Interpreter::print(), SeExpr2::ExprType::toString(), SeExpr2::ExprNode::type(), UseInterpreter, and SeExpr2::ExprType::valuesCompatible().

Referenced by prepIfNeeded().

## ◆ prepIfNeeded()

void SeExpr2::Expression::prepIfNeeded | ( |  | ) | const
| inline protected

Prepare, but only if not yet prepped

Definition at line 274 of file Expression.h.

References _prepped, and prep().

Referenced by SeExpr2::DExpression::DExpression(), evalFP(), evalMultiple(), evalStr(), isValid(), isVec(), and returnType().

## ◆ reset()

void Expression::reset | ( |  | ) |

Reset expr - force reparse/rebind

Definition at line 132 of file Expression.cpp.

References _comments, _envBuilder, _errors, _evaluationStrategy, _funcs, _interpreter, _isValid, _llvmEvaluator, _parsed, _parseError, _parseTree, _prepped, _threadUnsafeFunctionCalls, _vars, SeExpr2::ExprVarEnvBuilder::reset(), and UseInterpreter.

Referenced by setContext(), setDesiredReturnType(), setExpr(), setVarBlockCreator(), and ~Expression().

## ◆ resolveFunc()

virtual ExprFunc* SeExpr2::Expression::resolveFunc | ( | const std::string & | name | ) | const
| inline virtual

override resolveFunc to add external functions

Reimplemented in BasicExpression.

Definition at line 202 of file Expression.h.

Referenced by SeExpr2::ExprFuncNode::prep().

## ◆ resolveVar()

virtual ExprVarRef* SeExpr2::Expression::resolveVar | ( | const std::string & | name | ) | const
| inline virtual

override resolveVar to add external variables

Reimplemented in BasicExpression, and SeExpr2::DExpression.

Definition at line 199 of file Expression.h.

Referenced by SeExpr2::ExprVarNode::prep().

## ◆ returnType()

const ExprType & Expression::returnType | ( |  | ) | const

Return the return type of the expression. Currently may not match the type set in setReturnType. Expr will be parsed and variables and functions will be bound if needed.

Definition at line 299 of file Expression.cpp.

References _returnType, and prepIfNeeded().

Referenced by isConstant().

## ◆ setContext()

void Expression::setContext | ( | const Context & | context | ) |

Definition at line 154 of file Expression.cpp.

References _context, context(), and reset().

## ◆ setDesiredReturnType()

void Expression::setDesiredReturnType | ( | const ExprType & | type | ) |

Sets desired return value. This will allow the evaluation to potentially be optimized.

Definition at line 159 of file Expression.cpp.

References _desiredReturnType, and reset().

Referenced by ExprGrapherWidget::update().

## ◆ setExpr()

void Expression::setExpr | ( | const std::string & | e | ) |

Set expression string to e. This invalidates all parsed state.

Definition at line 169 of file Expression.cpp.

References _expression, and reset().

## ◆ setThreadUnsafe()

void SeExpr2::Expression::setThreadUnsafe | ( | const std::string & | functionName | ) | const
| inline

Internal function where parse tree nodes can register violations in thread safety with the main class.

Definition at line 166 of file Expression.h.

References _threadUnsafeFunctionCalls.

## ◆ setVarBlockCreator()

void Expression::setVarBlockCreator | ( | const VarBlockCreator * | varBlockCreator | ) |

Set variable block creator (lifetime of expression must be <= block)

Definition at line 164 of file Expression.cpp.

References _varBlockCreator, and reset().

## ◆ syntaxOK()

bool Expression::syntaxOK | ( |  | ) | const

Check expression syntax. Expr will be parsed if needed. If this returns false, the error message can be accessed via parseError()

Definition at line 174 of file Expression.cpp.

References _isValid, and parseIfNeeded().

## ◆ usesFunc()

bool Expression::usesFunc | ( | const std::string & | name | ) | const

Determine whether expression uses a particular function. Expr will be parsed if needed. No binding is required.

Definition at line 189 of file Expression.cpp.

References _funcs, and parseIfNeeded().

## ◆ usesVar()

bool Expression::usesVar | ( | const std::string & | name | ) | const

Determine whether expression uses a particular external variable. Expr will be parsed if needed. No binding is required.

Definition at line 184 of file Expression.cpp.

References _vars, and parseIfNeeded().

## ◆ varBlockCreator()

const VarBlockCreator* SeExpr2::Expression::varBlockCreator | ( |  | ) | const
| inline

Definition at line 231 of file Expression.h.

References _varBlockCreator.

Referenced by SeExpr2::ExprVarNode::prep().

## ◆ wantVec()

bool SeExpr2::Expression::wantVec | ( |  | ) | const
| inline

Get wantVec setting

Definition at line 172 of file Expression.h.

References _wantVec.

## Member Data Documentation

## ◆ _comments

std::vector<std::pair<int, int> > SeExpr2::Expression::_comments
| mutable private

Cached comments

Definition at line 291 of file Expression.h.

Referenced by addComment(), getComments(), parse(), and reset().

## ◆ _context

const Context* SeExpr2::Expression::_context
| private

Context for out of band function parameters

Definition at line 262 of file Expression.h.

Referenced by context(), and setContext().

## ◆ _desiredReturnType

ExprType SeExpr2::Expression::_desiredReturnType
| mutable protected

Computed return type.

Definition at line 266 of file Expression.h.

Referenced by debugPrintParseTree(), SeExpr2::DExpression::eval(), evalMultiple(), prep(), and setDesiredReturnType().

## ◆ _envBuilder

ExprVarEnvBuilder SeExpr2::Expression::_envBuilder
| mutable protected

Variable environment

Definition at line 269 of file Expression.h.

Referenced by prep(), and reset().

## ◆ _errors

std::vector<Error> SeExpr2::Expression::_errors
| mutable private

Cached parse error location {startline,startcolumn,endline,endcolumn}

Definition at line 288 of file Expression.h.

Referenced by addError(), getErrors(), prep(), and reset().

## ◆ _evaluationStrategy

EvaluationStrategy SeExpr2::Expression::_evaluationStrategy
| private

Definition at line 259 of file Expression.h.

Referenced by evalFP(), evalMultiple(), evalStr(), prep(), and reset().

## ◆ _expression

std::string SeExpr2::Expression::_expression
| private

The expression.

Definition at line 257 of file Expression.h.

Referenced by getExpr(), parse(), prep(), and setExpr().

## ◆ _funcs

std::set<std::string> SeExpr2::Expression::_funcs
| mutable private

Functions used in this expr

Definition at line 297 of file Expression.h.

Referenced by addFunc(), reset(), and usesFunc().

## ◆ _interpreter

Interpreter* SeExpr2::Expression::_interpreter
| mutable private

Interpreter

Definition at line 306 of file Expression.h.

Referenced by debugPrintInterpreter(), evalFP(), evalStr(), prep(), and reset().

## ◆ _isValid

bool SeExpr2::Expression::_isValid
| mutable private

Flag if we are valid or not

Definition at line 280 of file Expression.h.

Referenced by evalFP(), evalMultiple(), evalStr(), isValid(), isVec(), prep(), reset(), and syntaxOK().

## ◆ _llvmEvaluator

LLVMEvaluator* SeExpr2::Expression::_llvmEvaluator
| mutable private

Definition at line 310 of file Expression.h.

Referenced by debugPrintLLVM(), evalFP(), evalMultiple(), evalStr(), prep(), reset(), and ~Expression().

## ◆ _parsed

bool SeExpr2::Expression::_parsed
| mutable private

Flag set once expr is parsed/prepped (parsing is automatic and lazy)

Definition at line 282 of file Expression.h.

Referenced by parse(), parseIfNeeded(), and reset().

## ◆ _parseError

std::string SeExpr2::Expression::_parseError
| mutable private

Cached parse error (returned by isValid)

Definition at line 285 of file Expression.h.

Referenced by parse(), parseError(), prep(), and reset().

## ◆ _parseTree

ExprNode* SeExpr2::Expression::_parseTree
| mutable protected

Parse tree (null if syntax is bad).

Definition at line 271 of file Expression.h.

Referenced by debugPrintParseTree(), isVec(), parse(), prep(), and reset().

## ◆ _prepped

bool SeExpr2::Expression::_prepped
| mutable private

Definition at line 282 of file Expression.h.

Referenced by prep(), prepIfNeeded(), and reset().

## ◆ _returnSlot

int SeExpr2::Expression::_returnSlot
| mutable private

Definition at line 307 of file Expression.h.

Referenced by debugPrintInterpreter(), evalFP(), evalStr(), and prep().

## ◆ _returnType

ExprType SeExpr2::Expression::_returnType
| mutable private

Computed return type.

Definition at line 254 of file Expression.h.

Referenced by prep(), and returnType().

## ◆ _threadUnsafeFunctionCalls

std::vector<std::string> SeExpr2::Expression::_threadUnsafeFunctionCalls
| mutable private

Local variable table Whether or not we have unsafe functions

Definition at line 303 of file Expression.h.

Referenced by getThreadUnsafeFunctionCalls(), isThreadSafe(), reset(), and setThreadUnsafe().

## ◆ _varBlockCreator

const VarBlockCreator* SeExpr2::Expression::_varBlockCreator = 0
| private

Definition at line 313 of file Expression.h.

Referenced by setVarBlockCreator(), and varBlockCreator().

## ◆ _vars

std::set<std::string> SeExpr2::Expression::_vars
| mutable private

Variables used in this expr

Definition at line 294 of file Expression.h.

Referenced by addVar(), reset(), and usesVar().

## ◆ _wantVec

bool SeExpr2::Expression::_wantVec
| private

True if the expression wants a vector

Definition at line 251 of file Expression.h.

Referenced by isVec(), parse(), and wantVec().

## ◆ debugging

bool Expression::debugging = getenv("SE_EXPR_DEBUG") != 0
| static

Whether to debug expressions.

Definition at line 86 of file Expression.h.

Referenced by SeExpr2::ExprFuncStandard::buildInterpreter(), SeExpr2::chooseDefaultEvaluationStrategy(), and prep().

## ◆ defaultEvaluationStrategy

Expression::EvaluationStrategy Expression::defaultEvaluationStrategy = chooseDefaultEvaluationStrategy()
| static

What evaluation strategy to use by default.

Definition at line 84 of file Expression.h.

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

- /build/seexpr/src/SeExpr/src/SeExpr2/Expression.h
- /build/seexpr/src/SeExpr/src/SeExpr2/Expression.cpp