Go to the documentation of this file.
25 #include "ExprConfig.h"
48 std::cerr <<
"SeExpr2 Debug Mode Enabled " <<
56 #ifdef SEEXPR_ENABLE_LLVM
57 if (
char* env = getenv(
"SE_EXPR_EVAL")) {
58 if (
Expression::debugging) std::cerr <<
"Overriding SeExpr Evaluation Default to be " << env << std::endl;
83 sprintf(buf,
"%*s", depth * 2,
" ");
84 std::cout << buf <<
"'" << examinee->
toString() <<
"' " <<
typeid(*examinee).name()
91 : _wantVec(true), _expression(
""), _evaluationStrategy(evaluationStrategy), _context(&
Context::global()),
92 _desiredReturnType(
ExprType().FP(3).Varying()), _parseTree(0), _isValid(0), _parsed(0), _prepped(0),
101 : _wantVec(true), _expression(e), _evaluationStrategy(evaluationStrategy), _context(&
context),
102 _desiredReturnType(type), _parseTree(0), _isValid(0), _parsed(0), _prepped(0), _interpreter(0),
115 std::cerr <<
"return slot " <<
_returnSlot << std::endl;
197 int tempStartPos, tempEndPos;
206 #ifdef SEEXPR_PERFORMANCE
231 std::cerr <<
"Eval strategy is interpreter" << std::endl;
239 if (dimWanted > dimHave) {
251 std::cerr <<
"Eval strategy is llvm" << std::endl;
268 std::vector<int> lines;
272 if (*
p ==
'\n') lines.push_back(
static_cast<int>(
p - start));
275 lines.push_back(
static_cast<int>(
p - start));
277 std::stringstream sstream;
278 for (
unsigned int i = 0; i <
_errors.size(); i++) {
279 int* bound = std::lower_bound(&*lines.begin(), &*lines.end(),
_errors[i].startPos);
280 int line =
static_cast<int>(bound - &*lines.begin() + 1);
281 int lineStart = line == 1 ? 0 : lines[line - 1];
282 int col =
_errors[i].startPos - lineStart;
283 sstream <<
" Line " << line <<
" Col " << col <<
" - " <<
_errors[i].error << std::endl;
289 std::cerr <<
"ending with isValid " <<
_isValid << std::endl;
290 std::cerr <<
"parse error \n" <<
parseError() << std::endl;
314 static double noCrash[16] = {};
325 double* destBase =
reinterpret_cast<double**
>(varBlock->
data())[outputVarBlockOffset];
326 for (
size_t i = rangeStart; i < rangeEnd; i++) {
328 const double*
f =
evalFP(varBlock);
329 for (
int k = 0; k < dim; k++) {
330 destBase[dim * i + k] =
f[k];
void debugPrintInterpreter() const
bool usesVar(const std::string &name) const
static bool debugging
Whether to debug expressions.
const Context & context() const
std::vector< std::string > _threadUnsafeFunctionCalls
const std::string & parseError() const
const double * evalFP(VarBlock *varBlock)
void eval(VarBlock *varBlock, bool debug=false)
Evaluate program.
void parseIfNeeded() const
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
void setVarBlockCreator(const VarBlockCreator *varBlockCreator)
void endOp(bool execute=true)
A thread local evaluation context. Just allocate and fill in with data.
const ExprType & type() const
The type of the node.
int addOp(OpF op)
! adds an operator to the program (pointing to the data at the current location)
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd) const
Evaluate multiple blocks.
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd)
std::vector< double > d
Double data (constants and evaluated)
A class that lets you register for the variables used by one or more expressions.
std::vector< std::pair< int, int > > _comments
const char * evalStr(VarBlock *varBlock=nullptr) const
void setExpr(const std::string &e)
static void init()
call to define built-in funcs and load standard plugins
std::set< std::string > _vars
void debugPrintParseTree() const
std::string toString() const
Access to original string representation of current expression.
bool ExprParse(SeExpr2::ExprNode *&parseTree, std::string &error, int &errorStart, int &errorEnd, std::vector< std::pair< int, int > > &_comments, const SeExpr2::Expression *expr, const char *str, bool wantVec=true)
std::vector< double > d
copy of Interpreter's double data
bool isVec() const
True if node has a vector result.
ExprType _desiredReturnType
virtual bool examine(const SeExpr2::ExprNode *examinee)
SeExpr2::SPrintFuncX sprintf
void prepIfNeeded() const
Expression(EvaluationStrategy be=Expression::defaultEvaluationStrategy)
void reset()
Reset to factory state (one empty environment that is current)
bool isLifetimeConstant() const
validity check: type is not an error
std::vector< Error > _errors
EvaluationStrategy _evaluationStrategy
std::set< std::string > _funcs
void setContext(const Context &context)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
const ExprNode * parent() const
Access parent node - root node has no parent.
bool prepLLVM(ExprNode *parseTree, ExprType desiredReturnType)
ExprType & Error()
Mutate this into an error type.
int allocFP(int n)
! Allocate a floating point set of data of dimension n
bool isFP() const
Direct is predicate checks.
int indirectIndex
indirect index to add to pointer based data
std::vector< char * > s
constant and evaluated pointer data
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
std::string toString() const
Stringify the type into a printable string.
const ExprType & returnType() const
ExprVarEnvBuilder _envBuilder
Interpreter * _interpreter
static Expression::EvaluationStrategy chooseDefaultEvaluationStrategy()
void setDesiredReturnType(const ExprType &type)
EvaluationStrategy
Types of evaluation strategies that are available.
bool threadSafe
if true, interpreter's data will be copied to this instance before evaluation.
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
LLVMEvaluator * _llvmEvaluator
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
const double * evalFP(VarBlock *varBlock=nullptr) const
std::vector< char * > s
copy of Interpreter's str data
void addError(const std::string &error, const int startPos, const int endPos) const
char ** data()
Raw data of the data block pointer (used by compiler)
const VarBlockCreator * _varBlockCreator
If a scalar is used in a vector context
const char * evalStr(VarBlock *varBlock)
void debugPrintLLVM() const
void print(int pc=-1) const
Debug by printing program.
int addOperand(int param)
! Adds an operand. Note this should be done after doing the addOp!
bool usesFunc(const std::string &name) const
void walk(T_NODE *examinee)
Preorder walk.