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:
BasicExpression llvmexpr SeExpr2::DExpression

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 ExprTypereturnType () 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 ExprVarRefresolveVar (const std::string &name) const
 
virtual ExprFuncresolveFunc (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 Contextcontext () const
 
void setContext (const Context &context)
 
void debugPrintParseTree () const
 
void debugPrintInterpreter () const
 
void debugPrintLLVM () const
 
void setVarBlockCreator (const VarBlockCreator *varBlockCreator)
 
const VarBlockCreatorvarBlockCreator () 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)
 
Expressionoperator= (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

Types of evaluation strategies that are available.

Enumerator
UseInterpreter 
UseLLVM 

Definition at line 79 of file Expression.h.

Constructor & Destructor Documentation

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

Definition at line 85 of file Expression.cpp.

References SeExpr2::ExprFunc::init().

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

Definition at line 92 of file Expression.cpp.

References SeExpr2::ExprFunc::init().

Expression::~Expression ( )
virtual

Definition at line 102 of file Expression.cpp.

References _llvmEvaluator, and reset().

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

No definition by design.

Member Function Documentation

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

records a comment

Definition at line 210 of file Expression.h.

References _comments.

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().

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().

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().

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 setContext().

void Expression::debugPrintInterpreter ( ) const

Debug printout of interpreter evaluation program

Definition at line 107 of file Expression.cpp.

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

void Expression::debugPrintLLVM ( ) const

Debug printout of LLVM evaluation

Definition at line 114 of file Expression.cpp.

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

void Expression::debugPrintParseTree ( ) const

Debug printout of parse tree

Definition at line 116 of file Expression.cpp.

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

Referenced by prep().

const double * Expression::evalFP ( VarBlock varBlock = nullptr) const
void Expression::evalMultiple ( VarBlock varBlock,
int  outputVarBlockOffset,
size_t  rangeStart,
size_t  rangeEnd 
) const
const char * Expression::evalStr ( VarBlock varBlock = nullptr) const
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.

Referenced by SeExpr2::findComment().

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().

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::findComment(), and SeExpr2::ExprNode::toString().

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.

bool Expression::isConstant ( ) const

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

Definition at line 174 of file Expression.cpp.

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

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.

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(), ExprShortEdit::checkErrors(), main(), prep(), ExprGrapherView::update(), ExprDialog::verifiedAccept(), and ExprDialog::verifiedApply().

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 289 of file Expression.cpp.

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

Expression& SeExpr2::Expression::operator= ( const Expression e)
private
void Expression::parse ( ) const
private

Parse, and remember parse error if any

Definition at line 189 of file Expression.cpp.

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

Referenced by parseIfNeeded().

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 ExprShortEdit::checkErrors(), main(), and prep().

void SeExpr2::Expression::parseIfNeeded ( ) const
inlineprivate

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().

void Expression::prep ( ) const
private
void SeExpr2::Expression::prepIfNeeded ( ) const
inlineprotected

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().

void Expression::reset ( )
virtual ExprFunc* SeExpr2::Expression::resolveFunc ( const std::string &  name) const
inlinevirtual

override resolveFunc to add external functions

Reimplemented in BasicExpression.

Definition at line 202 of file Expression.h.

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

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

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().

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 294 of file Expression.cpp.

References _returnType, and prepIfNeeded().

Referenced by isConstant().

void Expression::setContext ( const Context context)

Definition at line 149 of file Expression.cpp.

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

void Expression::setDesiredReturnType ( const ExprType type)

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

Definition at line 154 of file Expression.cpp.

References _desiredReturnType, and reset().

Referenced by ExprGrapherWidget::update().

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

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

Definition at line 164 of file Expression.cpp.

References _expression, and reset().

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.

void Expression::setVarBlockCreator ( const VarBlockCreator varBlockCreator)

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

Definition at line 159 of file Expression.cpp.

References _varBlockCreator, and reset().

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 169 of file Expression.cpp.

References _isValid, and parseIfNeeded().

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 184 of file Expression.cpp.

References _funcs, and parseIfNeeded().

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 179 of file Expression.cpp.

References _vars, and parseIfNeeded().

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

Definition at line 231 of file Expression.h.

References _varBlockCreator.

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

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

Get wantVec setting

Definition at line 172 of file Expression.h.

References _wantVec.

Member Data Documentation

std::vector<std::pair<int, int> > SeExpr2::Expression::_comments
mutableprivate

Cached comments

Definition at line 291 of file Expression.h.

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

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().

ExprType SeExpr2::Expression::_desiredReturnType
mutableprotected

Computed return type.

Definition at line 266 of file Expression.h.

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

ExprVarEnvBuilder SeExpr2::Expression::_envBuilder
mutableprotected

Variable environment

Definition at line 269 of file Expression.h.

Referenced by prep(), and reset().

std::vector<Error> SeExpr2::Expression::_errors
mutableprivate

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

Definition at line 288 of file Expression.h.

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

EvaluationStrategy SeExpr2::Expression::_evaluationStrategy
private

Definition at line 259 of file Expression.h.

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

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

The expression.

Definition at line 257 of file Expression.h.

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

std::set<std::string> SeExpr2::Expression::_funcs
mutableprivate

Functions used in this expr

Definition at line 297 of file Expression.h.

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

Interpreter* SeExpr2::Expression::_interpreter
mutableprivate

Interpreter

Definition at line 306 of file Expression.h.

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

bool SeExpr2::Expression::_isValid
mutableprivate

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* SeExpr2::Expression::_llvmEvaluator
mutableprivate

Definition at line 310 of file Expression.h.

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

bool SeExpr2::Expression::_parsed
mutableprivate

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().

std::string SeExpr2::Expression::_parseError
mutableprivate

Cached parse error (returned by isValid)

Definition at line 285 of file Expression.h.

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

ExprNode* SeExpr2::Expression::_parseTree
mutableprotected

Parse tree (null if syntax is bad).

Definition at line 271 of file Expression.h.

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

bool SeExpr2::Expression::_prepped
mutableprivate

Definition at line 282 of file Expression.h.

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

int SeExpr2::Expression::_returnSlot
mutableprivate

Definition at line 307 of file Expression.h.

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

ExprType SeExpr2::Expression::_returnType
mutableprivate

Computed return type.

Definition at line 254 of file Expression.h.

Referenced by prep(), and returnType().

std::vector<std::string> SeExpr2::Expression::_threadUnsafeFunctionCalls
mutableprivate

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().

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

Definition at line 313 of file Expression.h.

Referenced by setVarBlockCreator(), and varBlockCreator().

std::set<std::string> SeExpr2::Expression::_vars
mutableprivate

Variables used in this expr

Definition at line 294 of file Expression.h.

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

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().

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().

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: