101 std::vector<ExprNode *>::iterator iter;
114 for (
auto & iter : surrogate->
_children) {
174 std::cerr <<
"after create localvar phi " << localVar->
getPhi() << std::endl;
225 bool returnWantsScalar =
false;
230 ExprType blockType = block->
prep(returnWantsScalar, functionEnv);
232 if (!error && blockType.
isValid()) {
236 "In function result of block '" + blockType.
toString() +
268 "Incorrect number of arguments to function call",
270 for (
int i = 0; i < callerNode->
numChildren(); i++) {
305 condType =
child(0)->
prep(
true, envBuilder);
312 thenType =
child(1)->
prep(
false, envBuilder);
313 thenEnv = envBuilder.
current();
315 elseType =
child(2)->
prep(
false, envBuilder);
316 elseEnv = envBuilder.
current();
363 max_child_d =
std::max(max_child_d, childType.
dim());
376 double first = f->value();
378 double second = s->value();
380 double third = t->value();
381 return {first, second, third};
412 condType =
child(0)->
prep(
true, envBuilder);
416 thenType =
child(1)->
prep(wantScalar, envBuilder);
417 elseType =
child(2)->
prep(wantScalar, envBuilder);
444 vecType =
child(0)->
prep(
false, envBuilder);
447 scriptType =
child(1)->
prep(
true, envBuilder);
466 firstType =
child(0)->
prep(
false, envBuilder);
468 secondType =
child(1)->
prep(
false, envBuilder);
491 firstType =
child(0)->
prep(
true, envBuilder);
493 secondType =
child(1)->
prep(
true, envBuilder);
517 firstType =
child(0)->
prep(
false, envBuilder);
518 secondType =
child(1)->
prep(
false, envBuilder);
526 setType((firstType.
isFP(1) ? secondType : firstType).setLifetime(firstType, secondType));
539 if (!phi->_thenVar->type().isError() && !phi->_elseVar->type().isError()) {
std::string unescapeString(const std::string &string)
const ExprLocalVar * localVar() const
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Node that calls a function.
bool checkArg(int argIndex, const ExprType &type, ExprVarEnvBuilder &envBuilder)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
std::vector< int > _promote
const ExprLocalFunctionNode * _localFunc
Extension function spec, used for complicated argument custom functions.
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const =0
Build an interpreter to evaluate the expression.
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &env) const =0
static const ExprFunc * lookup(const std::string &name)
Lookup a builtin function by name.
int maxArgs() const
return the maximum number of acceptable arguments
const ExprFuncX * funcx() const
return pointer to the funcx
int minArgs() const
return the minimum number of acceptable arguments
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Node that contains local function.
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Preps the definition of this site.
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
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
ExprNode(const Expression *expr)
bool checkIsFP(const ExprType &type, bool &error) const
Checks if the type is a float[d] for any d.
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
int numChildren() const
Number of children.
bool checkCondition(bool check, const ErrorCode message, const std::vector< std::string > &ids, bool &error) const
Checks the boolean value and records an error string with node if it is false.
std::vector< ExprNode * > _children
List of children.
bool checkIsValue(const ExprType &type, bool &error) const
Checks if the type is a value (i.e. string or float[d])
const ExprType & type() const
The type of the node.
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error) const
types match (true if they do)
void addError(const ErrorCode error, const std::vector< std::string > &ids={}) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
ExprNode * _parent
Parent node (null if this the the root)
const ExprNode * child(size_t i) const
Get 0 indexed child.
const Expression * _expr
Owning expression (node can't modify)
void setType(const ExprType &t)
Set type of parameter.
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
Node that stores a numeric constant.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Node that contains prototype of function.
std::vector< ExprType > _argTypes
void addArgs(ExprNode *surrogate)
ExprType returnType() const
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
void setReturnType(const ExprType &type)
void addArgTypes(ExprNode *surrogate)
bool isReturnTypeSet() const
const std::string & name() const
ExprStrNode(const Expression *expr, const char *str)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprType & String()
Mutate this into a string type.
ExprType & Constant()
Mutate this into a constant lifetime.
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
std::string toString() const
Stringify the type into a printable string.
bool isFP() const
Direct is predicate checks.
bool isLifeCompatible(const ExprType &o) const
ExprType & Error()
Mutate this into an error type.
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
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 * createDescendant(ExprVarEnv *parent)
Create a descendant scope from the provided parent, does not clobber current.
ExprVarEnv * current()
Return the current variable scope.
Variable scope for tracking variable lookup.
ExprLocalVar * find(const std::string &name)
Find a variable name by name (recursive to parents)
ExprLocalFunctionNode * findFunction(const std::string &name)
Find a function by name (recursive to parents)
void add(const std::string &name, std::unique_ptr< ExprLocalVar > var)
Add a variable refernece.
void resetAndSetParent(ExprVarEnv *parent)
Resets the scope (deletes all variables) and sets parent.
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
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
virtual ExprType type() const
returns (current) type
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
virtual ExprVarRef * resolveVar(const std::string &) const
virtual ExprFunc * resolveFunc(const std::string &) const
const VarBlockCreator * varBlockCreator() 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.
double max(double x, double y)
@ ConditionalTypesNotCompatible
"Types of conditional are not compatible",
@ UndeclaredFunction
"Function " << _name << " has no definition"
@ ArgumentTypeMismatch
"Expected "<< type << " for argument, got " << childType
@ BadAssignmentOperator
"Assignment operation has bad type: " << _type
@ FunctionTooManyArguments
"Too many args for function " << _name
@ Unknown
Unknown error (message = %1)
@ FunctionTooFewArguments
"Too few args for function " << _name
@ InconsistentDefinition
"Variable " << name() << " defined in conditionals inconsistently."