30 #include "ExprConfig.h"
190 inline bool checkCondition(
bool check,
const std::string& message,
bool& error) {
209 s <<
"Expected Float[" << d <<
"]" << std::endl;
218 false,
"Type mismatch. First: " + first.
toString() +
" Second: " + second.
toString(), error);
258 : ExprNode(expr), _name(name), _retTypeSet(true), _retType(retType), _argTypes() {}
261 : ExprNode(expr), _name(name), _retTypeSet(false), _argTypes() {}
265 void addArgTypes(ExprNode* surrogate);
266 void addArgs(ExprNode* surrogate);
278 return (_retTypeSet ? _retType :
ExprType().Error().Varying());
284 inline const ExprNode*
arg(
int i)
const {
288 const std::string&
name()
const {
return _name; }
294 int interpreterOps(
int c)
const {
return _interpreterOps.at(c); }
310 :
ExprNode(expr, prototype, block) {}
350 size_t _varEnvMergeIndex;
357 : ExprNode(expr, e), _name(name), _localVar(0) {}
364 const std::
string& name()
const {
368 return _assignedType;
467 : ExprNode(expr, type), _name(name), _localVar(0), _var(0) {}
472 const
char* name()
const {
return _name.c_str(); }
506 const
char* str()
const {
return _str.c_str(); }
507 void str(
const char* newstr) { _str = newstr; }
517 : ExprNode(expr), _name(name), _func(0), _localFunc(0), _data(0) {
527 const
char* name()
const {
return _name.c_str(); }
535 int nargs()
const {
return _nargs; }
538 double* scalarArgs()
const {
return &_scalarArgs[0]; }
539 Vec3d* vecArgs()
const {
return &_vecArgs[0]; }
542 Vec3d* evalArgs()
const;
545 Vec3d evalArg(
int n)
const;
548 bool isStrArg(
int n)
const;
551 std::string getStrArg(
int n)
const;
557 bool isStrArg(
int n)
const {
return n < numChildren() && dynamic_cast<const ExprStrNode*>(
child(n)) != 0; }
584 int promote(
int i)
const {
return _promote[i]; }
bool _isVec
True if node has a vector result.
Node that evaluates a conditional (if-then-else) expression.
Node that computes local variables before evaluating expression.
const ExprType & type() const
The type of the node.
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
ExprPrototypeNode(const Expression *expr, const std::string &name)
void setReturnType(const ExprType &type)
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
ExprNode * child(size_t i)
Get 0 indexed child.
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
void addError(const std::string &error, const int startPos, const int endPos) const
Node that constructs a vector from three scalars.
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
Data * getData() const
get associated blind data (returns 0 if none)
ExprVecNode(const Expression *expr)
bool isFP() const
Direct is predicate checks.
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
ExprLocalFunctionNode LocalFunction
Node that references a variable.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
Node that contains local function.
const ExprLocalVar * localVar() const
Function Definition, used in parse tree and func table.
Node that computes local variables before evaluating expression.
std::string toString() const
Stringify the type into a printable string.
std::vector< ExprType > _argTypes
short int endPos() const
Access end position in input string.
bool checkIsValue(const ExprType &type, bool &error)
Checks if the type is a value (i.e. string or float[d])
void str(const char *newstr)
virtual void eval(ArgHandle args)
short int length() const
Access length of input string.
bool isStrArg(int n) const
Node that evaluates a component of a vector.
Node that stores a string.
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.
Node that implements an binary operator.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
Node that contains entire program.
std::string getStrArg(int n) const
ExprVarNode(const Expression *expr, const char *name)
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
For any rgb or hsl value(except for negative s values)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
const Expression * _expr
Owning expression (node can't modify)
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself...
unsigned short int _endPos
ExprIfThenElseNode IfThenElse
Node that calls a function.
Variable scope for tracking variable lookup.
Vec< double, 3, false > Vec3d
short int startPos() const
Access start position in input string.
const ExprVarRef * var() const
ExprStrNode(const Expression *expr, const char *str)
const ExprLocalVar * localVar() const
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
const ExprNode * parent() const
Access parent node - root node has no parent.
const ExprNode * arg(int i) const
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
ExprModuleNode(const Expression *expr)
const ExprLocalFunctionNode * _localFunc
void setType(const ExprType &t)
Set type of parameter.
const std::string & name() const
ExprType & Constant()
Mutate this into a constant lifetime.
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
ExprPrototypeNode Prototype
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
base class for custom instance data
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
void removeLastChild()
Remove last child and delete the entry.
ExprNode * _parent
Parent node (null if this the the root)
Node that compute a local variable assignment.
int numChildren() const
Number of children.
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
ExprNode(const Expression *expr)
const ExprFunc * func() const
void addFunc(const char *n) const
add function evaluation (this is for internal use)
bool checkIsFP(int d, const ExprType &type, bool &error)
Checks if the type is a float[d] for a specific d.
Node that stores a numeric constant.
Node that implements a numeric comparison.
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
ExprType argType(int i) const
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
const Expression * expr() const
Access expression.
bool isReturnTypeSet() const
const ExprType & assignedType() const
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
Policy which provides all the AST Types for the parser.
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
NOde that computes with a single operand.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
Node that contains prototype of function.
ExprType returnType() const
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it mutable
const ExprNode * child(size_t i) const
Get 0 indexed child.
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
bool isVec() const
True if node has a vector result.
ExprFuncNode(const Expression *expr, const char *name)
std::string toString() const
Access to original string representation of current expression.
unsigned short int _startPos
Position line and collumn.
ExprUnaryOpNode(const Expression *expr, ExprNode *a, char op)
Construct with specific op ('!x' is logical negation, '~x' is 1-x, '-x' is -x)
ExprNumNode(const Expression *expr, double val)
ExprBinaryOpNode BinaryOp
std::vector< int > _interpreterOps
Node that implements a numeric/string comparison.
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
abstract class for implementing variable references
ExprCompareEqNode CompareEq
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
std::vector< ExprNode * > _children
List of children.
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...