Go to the documentation of this file.
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++) {
142 #if 0 // TODO: implement prototype
152 std::cerr <<
"after create localvar phi " << localVar->
getPhi() << std::endl;
156 checkCondition(
false,
"Prototypes are currently not supported", error);
191 #if 0 // TODO: no local functions for now
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)) {
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
std::string unescapeString(const std::string &string)
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &env) const =0
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)
ExprLocalVar * find(const std::string &name)
Find a variable name by name (recursive to parents)
ExprType returnType() const
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
int numChildren() const
Number of children.
const ExprType & type() const
The type of the node.
ExprLocalFunctionNode * findFunction(const std::string &name)
Find a function by name (recursive to parents)
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
const VarBlockCreator * varBlockCreator() const
virtual ExprFunc * resolveFunc(const std::string &name) const
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
A class that lets you register for the variables used by one or more expressions.
ExprStrNode(const Expression *expr, const char *str)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprVarEnv * createDescendant(ExprVarEnv *parent)
Create a descendant scope from the provided parent, does not clobber current.
Node that stores a numeric constant.
std::vector< int > _promote
bool isLifeCompatible(const ExprType &o) const
</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())
const char * name() const
ExprType & Constant()
Mutate this into a constant lifetime.
Extension function spec, used for complicated argument custom functions.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprLocalVar join (merge) references. Remembers which variables are possible assigners to this.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprNode * _parent
Parent node (null if this the the root)
Node that calls a function.
ExprType & String()
Mutate this into a string type.
ExprType type() const
returns type of the variable
Node that contains prototype of function.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
const ExprFuncX * funcx() const
return pointer to the funcx
Variable scope for tracking variable lookup.
void resetAndSetParent(ExprVarEnv *parent)
Resets the scope (deletes all variables) and sets parent.
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
int maxArgs() const
return the maximum number of acceptable arguments
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
const std::string & name() const
const ExprLocalFunctionNode * _localFunc
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprVarEnv * current()
Return the current variable scope.
ExprType & Error()
Mutate this into an error type.
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 ...
bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Preps the definition of this site.
void addArgs(ExprNode *surrogate)
bool isFP() const
Direct is predicate checks.
double max(double x, double y)
void add(const std::string &name, std::unique_ptr< ExprLocalVar > var)
Add a variable refernece.
Node that references a variable.
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
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.
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.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
void setReturnType(const ExprType &type)
std::string toString() const
Stringify the type into a printable string.
virtual ExprVarRef * resolveVar(const std::string &name) const
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const =0
Build an interpreter to evaluate the expression.
int minArgs() const
return the minimum number of acceptable arguments
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Vec< double, 3, false > Vec3d
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
Node that contains local function.
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
std::vector< ExprType > _argTypes
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
const ExprLocalVar * localVar() const
const ExprNode * child(size_t i) const
Get 0 indexed child.
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool isReturnTypeSet() const
virtual ExprType type() const
returns (current) type
void addVar(const char *n) const
add local variable (this is for internal use)
void setCurrent(ExprVarEnv *env)
Set a new current variable scope.
const ExprLocalVar * getPhi() const
get the primary representative phi node (i.e. the global parent of a dependent phi node)
const Expression * _expr
Owning expression (node can't modify)
</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")
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
void setType(const ExprType &t)
Set type of parameter.
void addArgTypes(ExprNode *surrogate)
ExprNode(const Expression *expr)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
std::vector< ExprNode * > _children
List of children.