KSeExpr 6.0.0.0
|
main expression class More...
#include <Expression.h>
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... | |
Static Public Attributes | |
static EvaluationStrategy | defaultEvaluationStrategy = chooseDefaultEvaluationStrategy() |
What evaluation strategy to use by default. | |
static bool | debugging = getenv("SE_EXPR_DEBUG") != nullptr |
Whether to debug expressions. | |
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 |
ErrorCode | _parseErrorCode |
std::vector< std::string > | _parseErrorIds |
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 |
main expression class
Definition at line 67 of file Expression.h.
Types of evaluation strategies that are available.
Enumerator | |
---|---|
UseInterpreter | |
UseLLVM |
Definition at line 70 of file Expression.h.
KSeExpr::Expression::Expression | ( | Expression::EvaluationStrategy | evaluationStrategy = Expression::defaultEvaluationStrategy | ) |
Definition at line 54 of file Expression.cpp.
References KSeExpr::ExprFunc::init().
KSeExpr::Expression::Expression | ( | const std::string & | e, |
const ExprType & | type = ExprType().FP(3) , |
||
EvaluationStrategy | be = Expression::defaultEvaluationStrategy , |
||
const Context & | context = Context::global() |
||
) |
Definition at line 61 of file Expression.cpp.
References KSeExpr::ExprFunc::init().
|
virtual |
Definition at line 71 of file Expression.cpp.
References _llvmEvaluator, and reset().
|
private |
No definition by design.
records a comment
Definition at line 212 of file Expression.h.
References _comments, and KSeExpr::length().
|
inline |
records an error in prep or parse stage
Definition at line 207 of file Expression.h.
References _errors.
Referenced by parse(), and KSeExpr::DExpression::resolveVar().
add function evaluation (this is for internal use)
Definition at line 326 of file Expression.h.
References _funcs.
add local variable (this is for internal use)
Definition at line 323 of file Expression.h.
References _vars.
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 218 of file Expression.h.
References _context.
Referenced by setContext().
void KSeExpr::Expression::debugPrintInterpreter | ( | ) | const |
Debug printout of interpreter evaluation program
Definition at line 76 of file Expression.cpp.
References _interpreter, _returnSlot, and KSeExpr::Interpreter::print().
void KSeExpr::Expression::debugPrintLLVM | ( | ) | const |
Debug printout of LLVM evaluation
Definition at line 83 of file Expression.cpp.
References _llvmEvaluator, and KSeExpr::LLVMEvaluator::debugPrint().
void KSeExpr::Expression::debugPrintParseTree | ( | ) | const |
Debug printout of parse tree
Definition at line 85 of file Expression.cpp.
References _desiredReturnType, _parseTree, KSeExpr::ExprType::toString(), and KSeExpr::ExprNode::type().
Referenced by prep().
Evaluates and returns float (check returnType()!)
Definition at line 269 of file Expression.cpp.
References _evaluationStrategy, _interpreter, _isValid, _llvmEvaluator, _returnSlot, KSeExpr::Interpreter::d, KSeExpr::Interpreter::eval(), KSeExpr::LLVMEvaluator::evalFP(), prepIfNeeded(), and UseInterpreter.
Referenced by KSeExpr::DExpression::eval(), and evalMultiple().
void KSeExpr::Expression::evalMultiple | ( | VarBlock * | varBlock, |
int | outputVarBlockOffset, | ||
size_t | rangeStart, | ||
size_t | rangeEnd | ||
) | const |
Evaluate multiple blocks.
Definition at line 283 of file Expression.cpp.
References _desiredReturnType, _evaluationStrategy, _isValid, _llvmEvaluator, KSeExpr::ExprType::dim(), evalFP(), KSeExpr::LLVMEvaluator::evalMultiple(), prepIfNeeded(), and UseInterpreter.
Evaluates and returns string (check returnType()!)
Definition at line 304 of file Expression.cpp.
References _evaluationStrategy, _interpreter, _isValid, _llvmEvaluator, _returnSlot, KSeExpr::Interpreter::eval(), KSeExpr::LLVMEvaluator::evalStr(), prepIfNeeded(), KSeExpr::Interpreter::s, and UseInterpreter.
Referenced by KSeExpr::DExpression::eval().
Get a reference to a list of the ranges where comments occurred
Definition at line 149 of file Expression.h.
References _comments.
Referenced by KSeExpr::findComment().
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 146 of file Expression.h.
References _errors.
|
inline |
Get the string that this expression is currently set to evaluate.
Definition at line 116 of file Expression.h.
References _expression.
Referenced by KSeExpr::findComment().
|
inline |
Returns a list of functions that are not threadSafe
Definition at line 171 of file Expression.h.
References _threadUnsafeFunctionCalls.
bool KSeExpr::Expression::isConstant | ( | ) | const |
Check if expression is constant. Expr will be parsed if needed. No binding is required.
Definition at line 144 of file Expression.cpp.
References parseIfNeeded(), and returnType().
|
inline |
Returns whether the expression contains and calls to non-threadsafe
Definition at line 164 of file Expression.h.
References _threadUnsafeFunctionCalls.
|
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 127 of file Expression.h.
References _isValid, and prepIfNeeded().
bool KSeExpr::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 259 of file Expression.cpp.
References _isValid, _parseTree, _wantVec, KSeExpr::ExprNode::isVec(), and prepIfNeeded().
|
private |
|
private |
Parse, and remember parse error if any
Definition at line 159 of file Expression.cpp.
References _comments, _expression, _parsed, _parseErrorCode, _parseErrorIds, _parseTree, _wantVec, addError(), and KSeExpr::ExprParse().
Referenced by parseIfNeeded().
Get parse error (if any). First call syntaxOK or isValid to parse (and optionally bind) the expression.
Definition at line 134 of file Expression.h.
References _parseErrorCode.
|
inline |
Get parse error message's arguments. First call syntaxOK or isValid to parse (and optionally bind) the expression. NOTE: These strings are NOT translatable.
Definition at line 142 of file Expression.h.
References _parseErrorIds.
|
inlineprivate |
Parse, but only if not yet parsed
Definition at line 244 of file Expression.h.
References _parsed, and parse().
Referenced by isConstant(), prep(), syntaxOK(), usesFunc(), and usesVar().
|
private |
Prepare expression (bind vars/functions, etc.) and remember error if any
Definition at line 169 of file Expression.cpp.
References _desiredReturnType, _envBuilder, _errors, _evaluationStrategy, _expression, _interpreter, _isValid, _llvmEvaluator, _parseTree, _prepped, _returnSlot, _returnType, KSeExpr::ExprNode::addError(), KSeExpr::Interpreter::addOp(), KSeExpr::Interpreter::addOperand(), KSeExpr::Interpreter::allocFP(), KSeExpr::ExprNode::buildInterpreter(), debugging, debugPrintParseTree(), KSeExpr::ExprType::dim(), KSeExpr::Interpreter::endOp(), KSeExpr::ExprType::Error(), KSeExpr::ExpressionIncompatibleTypes, KSeExpr::ExprType::isFP(), p, parseIfNeeded(), KSeExpr::ExprNode::prep(), KSeExpr::LLVMEvaluator::prepLLVM(), KSeExpr::Interpreter::print(), KSeExpr::ExprType::toString(), KSeExpr::ExprNode::type(), UseInterpreter, and KSeExpr::ExprType::valuesCompatible().
Referenced by prepIfNeeded().
|
inlineprotected |
Prepare, but only if not yet prepped
Definition at line 276 of file Expression.h.
References _prepped, and prep().
Referenced by KSeExpr::DExpression::DExpression(), evalFP(), evalMultiple(), evalStr(), isValid(), isVec(), and returnType().
void KSeExpr::Expression::reset | ( | ) |
Reset expr - force reparse/rebind
Definition at line 96 of file Expression.cpp.
References _comments, _envBuilder, _errors, _evaluationStrategy, _funcs, _interpreter, _isValid, _llvmEvaluator, _parsed, _parseErrorCode, _parseErrorIds, _parseTree, _prepped, _threadUnsafeFunctionCalls, _vars, KSeExpr::None, KSeExpr::ExprVarEnvBuilder::reset(), and UseInterpreter.
Referenced by setContext(), setDesiredReturnType(), setExpr(), setVarBlockCreator(), and ~Expression().
override resolveFunc to add external functions
Reimplemented in BasicExpression.
Definition at line 204 of file Expression.h.
|
inlinevirtual |
override resolveVar to add external variables
Reimplemented in KSeExpr::DExpression, and BasicExpression.
Definition at line 201 of file Expression.h.
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 264 of file Expression.cpp.
References _returnType, and prepIfNeeded().
Referenced by isConstant().
Definition at line 119 of file Expression.cpp.
Sets desired return value. This will allow the evaluation to potentially be optimized.
Definition at line 124 of file Expression.cpp.
References _desiredReturnType, and reset().
Set expression string to e. This invalidates all parsed state.
Definition at line 134 of file Expression.cpp.
References _expression, and reset().
Internal function where parse tree nodes can register violations in thread safety with the main class.
Definition at line 168 of file Expression.h.
References _threadUnsafeFunctionCalls.
void KSeExpr::Expression::setVarBlockCreator | ( | const VarBlockCreator * | varBlockCreator | ) |
Set variable block creator (lifetime of expression must be <= block)
Definition at line 129 of file Expression.cpp.
References _varBlockCreator, and reset().
bool KSeExpr::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 139 of file Expression.cpp.
References _isValid, and parseIfNeeded().
Determine whether expression uses a particular function. Expr will be parsed if needed. No binding is required.
Definition at line 154 of file Expression.cpp.
References _funcs, and parseIfNeeded().
Determine whether expression uses a particular external variable. Expr will be parsed if needed. No binding is required.
Definition at line 149 of file Expression.cpp.
References _vars, and parseIfNeeded().
|
inline |
Definition at line 233 of file Expression.h.
References _varBlockCreator.
|
inline |
Cached comments
Definition at line 296 of file Expression.h.
Referenced by addComment(), getComments(), parse(), and reset().
Context for out of band function parameters
Definition at line 264 of file Expression.h.
Referenced by context(), and setContext().
|
mutableprotected |
Computed return type.
Definition at line 268 of file Expression.h.
Referenced by debugPrintParseTree(), KSeExpr::DExpression::eval(), evalMultiple(), prep(), and setDesiredReturnType().
|
mutableprotected |
Variable environment
Definition at line 271 of file Expression.h.
|
mutableprivate |
Cached parse error location {startline,startcolumn,endline,endcolumn}
Definition at line 293 of file Expression.h.
Referenced by addError(), getErrors(), prep(), and reset().
|
private |
Definition at line 261 of file Expression.h.
Referenced by evalFP(), evalMultiple(), evalStr(), prep(), and reset().
|
private |
|
mutableprivate |
Functions used in this expr
Definition at line 302 of file Expression.h.
Referenced by addFunc(), reset(), and usesFunc().
|
mutableprivate |
Definition at line 311 of file Expression.h.
Referenced by debugPrintInterpreter(), evalFP(), evalStr(), prep(), and reset().
|
mutableprivate |
Flag if we are valid or not
Definition at line 282 of file Expression.h.
Referenced by evalFP(), evalMultiple(), evalStr(), isValid(), isVec(), prep(), reset(), and syntaxOK().
|
mutableprivate |
Definition at line 315 of file Expression.h.
Referenced by debugPrintLLVM(), evalFP(), evalMultiple(), evalStr(), prep(), reset(), and ~Expression().
|
mutableprivate |
Flag set once expr is parsed/prepped (parsing is automatic and lazy)
Definition at line 284 of file Expression.h.
Referenced by parse(), parseIfNeeded(), and reset().
|
mutableprivate |
Cached parse error (returned by isValid)
Definition at line 287 of file Expression.h.
Referenced by parse(), parseError(), and reset().
|
mutableprivate |
Cached parse error components (returned by isValid)
Definition at line 290 of file Expression.h.
Referenced by parse(), parseErrorArgs(), and reset().
|
mutableprotected |
Parse tree (null if syntax is bad).
Definition at line 273 of file Expression.h.
Referenced by debugPrintParseTree(), isVec(), parse(), prep(), and reset().
|
private |
Definition at line 284 of file Expression.h.
Referenced by prep(), prepIfNeeded(), and reset().
|
mutableprivate |
Definition at line 312 of file Expression.h.
Referenced by debugPrintInterpreter(), evalFP(), evalStr(), and prep().
|
mutableprivate |
Computed return type.
Definition at line 256 of file Expression.h.
Referenced by prep(), and returnType().
|
mutableprivate |
Local variable table Whether or not we have unsafe functions
Definition at line 308 of file Expression.h.
Referenced by getThreadUnsafeFunctionCalls(), isThreadSafe(), reset(), and setThreadUnsafe().
|
private |
Definition at line 318 of file Expression.h.
Referenced by setVarBlockCreator(), and varBlockCreator().
|
mutableprivate |
Variables used in this expr
Definition at line 299 of file Expression.h.
|
private |
True if the expression wants a vector
Definition at line 253 of file Expression.h.
Whether to debug expressions.
Definition at line 77 of file Expression.h.
Referenced by KSeExpr::ExprFuncStandard::buildInterpreter(), KSeExpr::chooseDefaultEvaluationStrategy(), and prep().
|
static |
What evaluation strategy to use by default.
Definition at line 75 of file Expression.h.