main expression class More...
#include <SeExpression.h>
Classes | |
struct | Error |
Represents a parse or type checking error in an expression. More... | |
Public Types | |
typedef std::map< std::string, SeExprLocalVarRef > | LocalVarTable |
Public Member Functions | |
SeExpression () | |
SeExpression (const std::string &e, bool wantVec=true) | |
virtual | ~SeExpression () |
void | setWantVec (bool wantVec) |
void | setExpr (const std::string &e) |
const std::string & | getExpr () const |
Get the string that this expression is currently set to evaluate. | |
bool | syntaxOK () const |
bool | isValid () const |
const std::string & | parseError () const |
const std::vector< Error > & | getErrors () 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 |
SeVec3d | evaluate () const |
void | reset () |
virtual SeExprVarRef * | resolveVar (const std::string &) const |
virtual SeExprFunc * | resolveFunc (const std::string &) const |
void | addError (const std::string &error, const int startPos, const int endPos) const |
const LocalVarTable & | getLocalVars () const |
void | addVar (const char *n) const |
add local variable (this is for internal use) | |
void | addFunc (const char *n) const |
add local function (this is for internal use) | |
SeExprVarRef * | resolveLocalVar (const char *n) const |
get local variable reference (this is for internal use) | |
SeExprLocalVarRef * | getLocalVar (const char *n) const |
Private Member Functions | |
SeExpression (const SeExpression &e) | |
SeExpression & | operator= (const SeExpression &e) |
void | parse () const |
void | prep () const |
void | parseIfNeeded () const |
void | prepIfNeeded () const |
Private Attributes | |
bool | _wantVec |
std::string | _expression |
SeExprNode * | _parseTree |
bool | _parsed |
bool | _prepped |
std::string | _parseError |
std::vector< Error > | _errors |
std::set< std::string > | _vars |
std::set< std::string > | _funcs |
LocalVarTable | _localVars |
std::vector< std::string > | _threadUnsafeFunctionCalls |
std::vector< char * > | _stringTokens |
main expression class
Definition at line 71 of file SeExpression.h.
typedef std::map<std::string, SeExprLocalVarRef> SeExpression::LocalVarTable |
Definition at line 74 of file SeExpression.h.
SeExpression::SeExpression | ( | ) |
Definition at line 25 of file SeExpression.cpp.
References SeExprFunc::init().
SeExpression::SeExpression | ( | const std::string & | e, | |
bool | wantVec = true | |||
) |
Definition at line 32 of file SeExpression.cpp.
References SeExprFunc::init().
SeExpression::~SeExpression | ( | ) | [virtual] |
Definition at line 39 of file SeExpression.cpp.
References reset().
SeExpression::SeExpression | ( | const SeExpression & | e | ) | [private] |
No definition by design.
void SeExpression::addError | ( | const std::string & | error, | |
const int | startPos, | |||
const int | endPos | |||
) | const [inline] |
records an error in prep or parse stage
Definition at line 175 of file SeExpression.h.
References _errors.
Referenced by SeExprNode::addError(), and parse().
void SeExpression::addFunc | ( | const char * | n | ) | const [inline] |
add local function (this is for internal use)
Definition at line 238 of file SeExpression.h.
References _funcs.
Referenced by SeExprFuncNode::SeExprFuncNode().
void SeExpression::addVar | ( | const char * | n | ) | const [inline] |
add local variable (this is for internal use)
Definition at line 235 of file SeExpression.h.
References _vars.
Referenced by SeExprVarNode::SeExprVarNode().
SeVec3d SeExpression::evaluate | ( | ) | const |
Evaluate the expression. This will parse and bind if needed
Definition at line 155 of file SeExpression.cpp.
References _localVars, _parseTree, _wantVec, SeExprNode::eval(), isVec(), and prepIfNeeded().
Referenced by SeExprEdGrapherView::update().
const std::vector<Error>& SeExpression::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 126 of file SeExpression.h.
References _errors.
Referenced by SeExprEdDialog::applyExpression().
const std::string& SeExpression::getExpr | ( | ) | const [inline] |
Get the string that this expression is currently set to evaluate.
Definition at line 107 of file SeExpression.h.
References _expression.
SeExprLocalVarRef* SeExpression::getLocalVar | ( | const char * | n | ) | const [inline] |
get local variable reference. This is potentially useful for expression debuggers and/or uses of expressions where mutable variables are desired
Definition at line 249 of file SeExpression.h.
References _localVars.
Referenced by SeExprAssignNode::prep().
const LocalVarTable& SeExpression::getLocalVars | ( | ) | const [inline] |
Returns a read only map of local variables that were set
Definition at line 179 of file SeExpression.h.
References _localVars.
const std::vector<std::string>& SeExpression::getThreadUnsafeFunctionCalls | ( | ) | const [inline] |
Returns a list of functions that are not threadSafe
Definition at line 151 of file SeExpression.h.
References _threadUnsafeFunctionCalls.
bool SeExpression::isConstant | ( | ) | const |
Check if expression is constant. Expr will be parsed if needed. No binding is required.
Definition at line 84 of file SeExpression.cpp.
References _funcs, _vars, and parseIfNeeded().
bool SeExpression::isThreadSafe | ( | ) | const [inline] |
Returns whether the expression contains and calls to non-threadsafe
Definition at line 142 of file SeExpression.h.
References _threadUnsafeFunctionCalls.
bool SeExpression::isValid | ( | ) | const |
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 78 of file SeExpression.cpp.
References _parseTree, and prepIfNeeded().
Referenced by SeExprEdDialog::applyExpression(), SeExprEdShortEdit::checkErrors(), SeExprEdGrapherView::update(), SeExprEdDialog::verifiedAccept(), and SeExprEdDialog::verifiedApply().
bool SeExpression::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 148 of file SeExpression.cpp.
References _parseTree, _wantVec, SeExprNode::isVec(), and prepIfNeeded().
Referenced by evaluate().
SeExpression& SeExpression::operator= | ( | const SeExpression & | e | ) | [private] |
void SeExpression::parse | ( | ) | const [private] |
Parse, and remember parse error if any
Definition at line 103 of file SeExpression.cpp.
References _expression, _parsed, _parseError, _parseTree, _stringTokens, addError(), and SeExprParse().
Referenced by parseIfNeeded().
const std::string& SeExpression::parseError | ( | ) | const [inline] |
Get parse error (if any). First call syntaxOK or isValid to parse (and optionally bind) the expression.
Definition at line 122 of file SeExpression.h.
References _parseError.
Referenced by SeExprEdShortEdit::checkErrors().
void SeExpression::parseIfNeeded | ( | ) | const [inline, private] |
Parse, but only if not yet parsed
Definition at line 194 of file SeExpression.h.
References _parsed, and parse().
Referenced by isConstant(), prep(), syntaxOK(), usesFunc(), and usesVar().
void SeExpression::prep | ( | ) | const [private] |
Prepare expression (bind vars/functions, etc.) and remember error if any
Definition at line 116 of file SeExpression.cpp.
References _errors, _expression, _parseError, _parseTree, _prepped, p, parseIfNeeded(), SeExprNode::prep(), and wantVec().
Referenced by prepIfNeeded().
void SeExpression::prepIfNeeded | ( | ) | const [inline, private] |
Prepare, but only if not yet prepped
Definition at line 197 of file SeExpression.h.
References _prepped, and prep().
Referenced by evaluate(), isValid(), and isVec().
void SeExpression::reset | ( | ) |
Reset expr - force reparse/rebind
Definition at line 44 of file SeExpression.cpp.
References _errors, _funcs, _localVars, _parsed, _parseError, _parseTree, _prepped, _stringTokens, _threadUnsafeFunctionCalls, and _vars.
Referenced by setExpr(), setWantVec(), and ~SeExpression().
virtual SeExprFunc* SeExpression::resolveFunc | ( | const std::string & | ) | const [inline, virtual] |
override resolveFunc to add external functions
Reimplemented in SeExprEdExpression.
Definition at line 172 of file SeExpression.h.
Referenced by SeExprFuncNode::prep().
SeExprVarRef* SeExpression::resolveLocalVar | ( | const char * | n | ) | const [inline] |
get local variable reference (this is for internal use)
Definition at line 241 of file SeExpression.h.
References _localVars.
Referenced by SeExprVarNode::prep().
virtual SeExprVarRef* SeExpression::resolveVar | ( | const std::string & | ) | const [inline, virtual] |
override resolveVar to add external variables
Reimplemented in SeExprEdExpression.
Definition at line 169 of file SeExpression.h.
Referenced by SeExprVarNode::prep().
void SeExpression::setExpr | ( | const std::string & | e | ) |
Set expression string to e. This invalidates all parsed state.
Reimplemented in SeExprEdExpression.
Definition at line 66 of file SeExpression.cpp.
References _expression, and reset().
void SeExpression::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 147 of file SeExpression.h.
References _threadUnsafeFunctionCalls.
Referenced by SeExprFuncNode::prep().
void SeExpression::setWantVec | ( | bool | wantVec | ) |
Sets the expression to desire a vector or a scalar. This will allow the evaluation to potentially be optimized if only a scalar is desired.
Definition at line 60 of file SeExpression.cpp.
References _wantVec, and reset().
Referenced by SeExprEdGrapherWidget::update().
bool SeExpression::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 72 of file SeExpression.cpp.
References _parseTree, and parseIfNeeded().
bool SeExpression::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 96 of file SeExpression.cpp.
References _funcs, and parseIfNeeded().
bool SeExpression::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 90 of file SeExpression.cpp.
References _vars, and parseIfNeeded().
bool SeExpression::wantVec | ( | ) | const [inline] |
Get wantVec setting
Definition at line 155 of file SeExpression.h.
References _wantVec.
Referenced by prep().
std::vector<Error> SeExpression::_errors [mutable, private] |
Cached parse error location {startline,startcolumn,endline,endcolumn}
Definition at line 215 of file SeExpression.h.
Referenced by addError(), getErrors(), prep(), and reset().
std::string SeExpression::_expression [private] |
std::set<std::string> SeExpression::_funcs [mutable, private] |
Functions used in this expr
Definition at line 221 of file SeExpression.h.
Referenced by addFunc(), isConstant(), reset(), and usesFunc().
LocalVarTable SeExpression::_localVars [mutable, private] |
Local variable table
Definition at line 224 of file SeExpression.h.
Referenced by evaluate(), getLocalVar(), getLocalVars(), reset(), and resolveLocalVar().
bool SeExpression::_parsed [mutable, private] |
Flag set once expr is parsed/prepped (parsing is automatic and lazy)
Definition at line 209 of file SeExpression.h.
Referenced by parse(), parseIfNeeded(), and reset().
std::string SeExpression::_parseError [mutable, private] |
Cached parse error (returned by isValid)
Definition at line 212 of file SeExpression.h.
Referenced by parse(), parseError(), prep(), and reset().
SeExprNode* SeExpression::_parseTree [mutable, private] |
Parse tree (null if syntax is bad).
Definition at line 206 of file SeExpression.h.
Referenced by evaluate(), isValid(), isVec(), parse(), prep(), reset(), and syntaxOK().
bool SeExpression::_prepped [mutable, private] |
Definition at line 209 of file SeExpression.h.
Referenced by prep(), prepIfNeeded(), and reset().
std::vector<char*> SeExpression::_stringTokens [mutable, private] |
String tokens allocated by lex
Definition at line 230 of file SeExpression.h.
std::vector<std::string> SeExpression::_threadUnsafeFunctionCalls [mutable, private] |
Whether or not we have unsafe functions
Definition at line 227 of file SeExpression.h.
Referenced by getThreadUnsafeFunctionCalls(), isThreadSafe(), reset(), and setThreadUnsafe().
std::set<std::string> SeExpression::_vars [mutable, private] |
Variables used in this expr
Definition at line 218 of file SeExpression.h.
Referenced by addVar(), isConstant(), reset(), and usesVar().
bool SeExpression::_wantVec [private] |
True if the expression wants a vector
Definition at line 200 of file SeExpression.h.
Referenced by evaluate(), isVec(), setWantVec(), and wantVec().