51 : _expr(
expr), _parent(0), _isVec(0), _type(type) {
63 : _expr(
expr), _parent(0), _isVec(0), _type(type) {
77 : _expr(
expr), _parent(0), _isVec(0), _type(type) {
86 std::vector<ExprNode*>::iterator iter;
96 std::vector<ExprNode*>::iterator iter;
97 for (iter = surrogate->
_children.begin(); iter != surrogate->
_children.end(); iter++) {
152 std::cerr <<
"after create localvar phi " << localVar->
getPhi() << std::endl;
156 checkCondition(
false,
"Prototypes are currently not supported", error);
200 bool returnWantsScalar =
false;
205 ExprType blockType = block->
prep(returnWantsScalar, functionEnv);
207 if (!error && blockType.
isValid()) {
211 "In function result of block '" + blockType.
toString() +
226 checkCondition(
false,
"Local functions are currently not supported.", error);
242 "Incorrect number of arguments to function call",
244 for (
int i = 0; i < callerNode->
numChildren(); i++) {
253 callerNode->
checkCondition(
false,
"Local functions are currently not supported.", error);
271 ExprType condType, thenType, elseType;
275 condType =
child(0)->
prep(
true, envBuilder);
282 thenType =
child(1)->
prep(
false, envBuilder);
283 thenEnv = envBuilder.
current();
285 elseType =
child(2)->
prep(
false, envBuilder);
286 elseEnv = envBuilder.
current();
332 max_child_d = std::max(max_child_d, childType.
dim());
344 double first =
f->value();
346 double second = s->value();
348 double third = t->value();
349 return Vec3d(first, second, third);
372 ExprType condType, thenType, elseType;
376 condType =
child(0)->
prep(
true, envBuilder);
380 thenType =
child(1)->
prep(wantScalar, envBuilder);
381 elseType =
child(2)->
prep(wantScalar, envBuilder);
406 vecType =
child(0)->
prep(
false, envBuilder);
409 scriptType =
child(1)->
prep(
true, envBuilder);
426 firstType =
child(0)->
prep(
false, envBuilder);
428 secondType =
child(1)->
prep(
false, envBuilder);
448 firstType =
child(0)->
prep(
true, envBuilder);
450 secondType =
child(1)->
prep(
true, envBuilder);
471 firstType =
child(0)->
prep(
false, envBuilder);
472 secondType =
child(1)->
prep(
false, envBuilder);
480 setType((firstType.
isFP(1) ? secondType : firstType).setLifetime(firstType, secondType));
492 if (!phi->_thenVar->type().isError() && !phi->_elseVar->type().isError()) {
493 addError(std::string(
"Variable ") +
name() +
" defined in conditionals inconsistently.");
554 nargs <= _func->maxArgs() ||
_func->
maxArgs() < 0,
"Too many args for function " +
_name, error)) {
std::string unescapeString(const std::string &string)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
const ExprLocalVar * localVar() const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Node that calls a function.
const ExprLocalFunctionNode * _localFunc
std::vector< int > _promote
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder &envBuilder)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Extension function spec, used for complicated argument custom functions.
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &env) const =0
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const =0
Build an interpreter to evaluate the expression.
int maxArgs() const
return the maximum number of acceptable arguments
const ExprFuncX * funcx() const
return pointer to the funcx
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
int minArgs() const
return the minimum number of acceptable arguments
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Node that contains local function.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Preps the definition of this site.
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
ExprLocalVar join (merge) references. Remembers which variables are possible assigners to this.
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
const ExprLocalVar * getPhi() const
get the primary representative phi node (i.e. the global parent of a dependent phi node)
ExprType type() const
returns type of the variable
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
std::vector< ExprNode * > _children
List of children.
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
void setType(const ExprType &t)
Set type of parameter.
int numChildren() const
Number of children.
ExprNode * _parent
Parent node (null if this the the root)
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
ExprNode(const Expression *expr)
const ExprNode * child(size_t i) const
Get 0 indexed child.
const ExprType & type() const
The type of the node.
const Expression * _expr
Owning expression (node can't modify)
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
bool checkCondition(bool check, const std::string &message, bool &error)
Checks the boolean value and records an error string with node if it is false.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
Node that stores a numeric constant.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Node that contains prototype of function.
ExprType returnType() const
void addArgs(ExprNode *surrogate)
void addArgTypes(ExprNode *surrogate)
void setReturnType(const ExprType &type)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool isReturnTypeSet() const
std::vector< ExprType > _argTypes
const std::string & name() const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprStrNode(const Expression *expr, const char *str)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
std::string toString() const
Stringify the type into a printable string.
bool isFP() const
Direct is predicate checks.
ExprType & String()
Mutate this into a string type.
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
bool isLifeCompatible(const ExprType &o) const
ExprType & Error()
Mutate this into an error type.
ExprType & Constant()
Mutate this into a constant lifetime.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
void setCurrent(ExprVarEnv *env)
Set a new current variable scope.
ExprVarEnv * current()
Return the current variable scope.
ExprVarEnv * createDescendant(ExprVarEnv *parent)
Create a descendant scope from the provided parent, does not clobber current.
Variable scope for tracking variable lookup.
void add(const std::string &name, std::unique_ptr< ExprLocalVar > var)
Add a variable refernece.
ExprLocalVar * find(const std::string &name)
Find a variable name by name (recursive to parents)
void resetAndSetParent(ExprVarEnv *parent)
Resets the scope (deletes all variables) and sets parent.
ExprLocalFunctionNode * findFunction(const std::string &name)
Find a function by name (recursive to parents)
size_t mergeBranches(const ExprType &type, ExprVarEnv &env1, ExprVarEnv &env2)
Add all variables into scope by name, but modify their lifetimes to the given type's lifetime.
Node that references a variable.
const char * name() const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType type() const
returns (current) type
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprVarRef * resolveVar(const std::string &name) const
const VarBlockCreator * varBlockCreator() const
virtual ExprFunc * resolveFunc(const std::string &name) const
void addVar(const char *n) const
add local variable (this is for internal use)
A class that lets you register for the variables used by one or more expressions.
Vec< double, 3, false > Vec3d
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")
</pre > there might be errors in the expression you must check with isValid() before you can evaluate. Then you can print a parse error as well< pre > if(!expr.isValid())
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
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)