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()
115 std::cerr <<
"return slot " <<
_returnSlot << std::endl;
124 std::cerr <<
"Parse tree desired type " <<
_desiredReturnType.toString() <<
" actual "
125 <<
_parseTree->type().toString() << 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];
334 _llvmEvaluator->evalMultiple(varBlock, outputVarBlockOffset, rangeStart, rangeEnd);
static void init()
call to define built-in funcs and load standard plugins
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.
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.
ExprType & Error()
Mutate this into an error type.
bool isLifetimeConstant() const
validity check: type is not an error
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
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()
Walker< true > ConstWalker
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)
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)