49 : _expr(expr), _parent(0), _isVec(0), _type(type) {
61 : _expr(expr), _parent(0), _isVec(0), _type(type) {
75 : _expr(expr), _parent(0), _isVec(0), _type(type) {
84 std::vector<ExprNode*>::iterator iter;
94 std::vector<ExprNode*>::iterator iter;
95 for (iter = surrogate->
_children.begin(); iter != surrogate->
_children.end(); iter++) {
140 checkCondition(
false,
"Prototypes are currently not supported",error);
154 std::cerr <<
"after create localvar phi " << localVar->
getPhi() << std::endl;
181 child = this->
child(i);
182 type = child->
type();
191 #if 0 // TODO: no local functions for now
198 if (!prototype->
prep(
false, functionEnv).
isValid()) error =
true;
201 bool returnWantsScalar =
false;
206 ExprType blockType = block->
prep(returnWantsScalar, functionEnv);
208 if (!error && blockType.
isValid()) {
212 "In function result of block '" + blockType.
toString() +
221 env.addFunction(prototype->
name(),
this);
229 checkCondition(
false,
"Local functions are currently not supported.",error);
239 "Incorrect number of arguments to function call",
241 for (
int i = 0; i < callerNode->
numChildren(); i++) {
250 callerNode->
checkCondition(
false,
"Local functions are currently not supported.",error);
268 ExprType condType, thenType, elseType;
272 condType =
child(0)->
prep(
true, envBuilder);
279 thenType =
child(1)->
prep(
false, envBuilder);
282 elseType =
child(2)->
prep(
false, envBuilder);
330 max_child_d =
std::max(max_child_d, childType.
dim());
342 double first =
f->value();
344 double second = s->value();
346 double third = t->value();
347 return Vec3d(first, second, third);
370 ExprType condType, thenType, elseType;
374 condType =
child(0)->
prep(
true, envBuilder);
378 thenType =
child(1)->
prep(wantScalar, envBuilder);
379 elseType =
child(2)->
prep(wantScalar, envBuilder);
404 vecType =
child(0)->
prep(
false, envBuilder);
407 scriptType =
child(1)->
prep(
true, envBuilder);
424 firstType =
child(0)->
prep(
false, envBuilder);
426 secondType =
child(1)->
prep(
false, envBuilder);
446 firstType =
child(0)->
prep(
true, envBuilder);
448 secondType =
child(1)->
prep(
true, envBuilder);
468 firstType =
child(0)->
prep(
false, envBuilder);
470 secondType =
child(1)->
prep(
false, envBuilder);
477 setType((firstType.
isFP(1) ? secondType : firstType).setLifetime(firstType, secondType));
489 if(!phi->_thenVar->type().isError() && !phi->_elseVar->type().isError()){
490 addError(std::string(
"Variable ")+
name()+
" defined in conditionals inconsistently.");
548 nargs <= _func->maxArgs() ||
_func->
maxArgs() < 0,
"Too many args for function " +
_name, error)) {
576 if (type.
isFP() && type.
dim() > childType.
dim()) {
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Preps the definition of this site.
const ExprType & type() const
The type of the node.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
ExprType & Varying()
Mutate this into a varying lifetime.
const char * name() const
virtual ExprVarRef * resolveVar(const std::string &name) const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const =0
Build an interpreter to evaluate the expression.
void setReturnType(const ExprType &type)
</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")
const ExprFuncX * funcx() const
return pointer to the funcx
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
void addArgs(ExprNode *surrogate)
int maxArgs() const
return the maximum number of acceptable arguments
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool isFP() const
Direct is predicate checks.
Node that references a variable.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprType type() const
returns type of the variable
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprType & String()
Mutate this into a string type.
Node that contains local function.
const ExprLocalVar * localVar() const
std::string toString() const
Stringify the type into a printable string.
std::vector< ExprType > _argTypes
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
void add(const std::string &name, std::unique_ptr< ExprLocalVar > var)
Add a variable refernece.
std::vector< int > _promote
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.
ExprVarEnv * createDescendant(ExprVarEnv *parent)
Create a descendant scope from the provided parent, does not clobber current.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
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)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
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 wantScalar, ExprVarEnvBuilder &envBuilder)
const Expression * _expr
Owning expression (node can't modify)
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
double max(double x, double y)
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself...
Node that calls a function.
Variable scope for tracking variable lookup.
const ExprLocalVar * getPhi() const
get the primary representative phi node (i.e. the global parent of a dependent phi node) ...
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
A class that lets you register for the variables used by one or more expressions. ...
void addArgTypes(ExprNode *surrogate)
Vec< double, 3, false > Vec3d
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
bool checkArg(int argIndex, ExprType type, ExprVarEnvBuilder &envBuilder)
void addVar(const char *n) const
add local variable (this is for internal use)
const ExprLocalFunctionNode * _localFunc
void setType(const ExprType &t)
Set type of parameter.
const std::string & name() const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprType & Constant()
Mutate this into a constant lifetime.
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &env) const =0
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
ExprNode * _parent
Parent node (null if this the the root)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
int numChildren() const
Number of children.
ExprLocalVar * find(const std::string &name)
Find a variable name by name (recursive to parents)
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
ExprNode(const Expression *expr)
const VarBlockCreator * varBlockCreator() const
Node that stores a numeric constant.
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
ExprLocalFunctionNode * findFunction(const std::string &name)
Find a function by name (recursive to parents)
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
ExprVarEnv * current()
Return the current variable scope.
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
bool isReturnTypeSet() const
void resetAndSetParent(ExprVarEnv *parent)
Resets the scope (deletes all variables) and sets parent.
ExprLocalVar join (merge) references. Remembers which variables are possible assigners to this...
Node that contains prototype of function.
ExprType returnType() const
const ExprNode * child(size_t i) const
Get 0 indexed child.
virtual ExprFunc * resolveFunc(const std::string &name) const
virtual ExprType type() const
returns (current) type
bool isLifeCompatible(const ExprType &o) const
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Extension function spec, used for complicated argument custom functions.
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
int minArgs() const
return the minimum number of acceptable arguments
ExprType & None()
Mutate this into a none type.
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
void setCurrent(ExprVarEnv *env)
Set a new current variable scope.
ExprType & Error()
Mutate this into an error type.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
std::vector< ExprNode * > _children
List of children.
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
</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())
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...