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];
static void init()
call to define built-in funcs and load standard plugins
bool isVec() const
True if node has a vector result.
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
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.
std::string toString() const
Access to original string representation of current expression.
const ExprType & type() const
The type of the node.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
std::string toString() const
Stringify the type into a printable string.
bool isFP() const
Direct is predicate checks.
ExprType & Error()
Mutate this into an error type.
bool isLifetimeConstant() const
validity check: type is not an error
void reset()
Reset to factory state (one empty environment that is current)
void parseIfNeeded() const
bool usesVar(const std::string &name) const
const Context & context() const
void setDesiredReturnType(const ExprType &type)
Interpreter * _interpreter
const VarBlockCreator * _varBlockCreator
std::vector< std::pair< int, int > > _comments
EvaluationStrategy
Types of evaluation strategies that are available.
Expression(EvaluationStrategy be=Expression::defaultEvaluationStrategy)
std::vector< Error > _errors
const char * evalStr(VarBlock *varBlock=nullptr) const
std::set< std::string > _funcs
EvaluationStrategy _evaluationStrategy
const ExprType & returnType() const
void setExpr(const std::string &e)
void addError(const std::string &error, const int startPos, const int endPos) const
LLVMEvaluator * _llvmEvaluator
bool usesFunc(const std::string &name) const
std::set< std::string > _vars
void setVarBlockCreator(const VarBlockCreator *varBlockCreator)
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd) const
Evaluate multiple blocks.
const double * evalFP(VarBlock *varBlock=nullptr) const
void debugPrintLLVM() const
const std::string & parseError() const
void setContext(const Context &context)
ExprType _desiredReturnType
static EvaluationStrategy defaultEvaluationStrategy
What evaluation strategy to use by default.
void debugPrintInterpreter() const
static bool debugging
Whether to debug expressions.
void prepIfNeeded() const
std::vector< std::string > _threadUnsafeFunctionCalls
void debugPrintParseTree() const
ExprVarEnvBuilder _envBuilder
int allocFP(int n)
! Allocate a floating point set of data of dimension n
int addOp(OpF op)
! adds an operator to the program (pointing to the data at the current location)
void eval(VarBlock *varBlock, bool debug=false)
Evaluate program.
int addOperand(int param)
! Adds an operand. Note this should be done after doing the addOp!
void endOp(bool execute=true)
std::vector< double > d
Double data (constants and evaluated)
std::vector< char * > s
constant and evaluated pointer data
void print(int pc=-1) const
Debug by printing program.
const char * evalStr(VarBlock *varBlock)
void evalMultiple(VarBlock *varBlock, int outputVarBlockOffset, size_t rangeStart, size_t rangeEnd)
bool prepLLVM(ExprNode *parseTree, ExprType desiredReturnType)
const double * evalFP(VarBlock *varBlock)
virtual bool examine(const SeExpr2::ExprNode *examinee)
A class that lets you register for the variables used by one or more expressions.
A thread local evaluation context. Just allocate and fill in with data.
std::vector< double > d
copy of Interpreter's double data
int indirectIndex
indirect index to add to pointer based data
char ** data()
Raw data of the data block pointer (used by compiler)
bool threadSafe
if true, interpreter's data will be copied to this instance before evaluation.
std::vector< char * > s
copy of Interpreter's str data
void walk(T_NODE *examinee)
Preorder walk.
T_FUNCTYPE getTemplatizedOp(int i)
Return the function f encapsulated in class T for the dynamic i converted to a static d.
SeExpr2::SPrintFuncX sprintf
static Expression::EvaluationStrategy chooseDefaultEvaluationStrategy()
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)
If a scalar is used in a vector context
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)