Go to the documentation of this file.
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);
365 const std::string&
name()
const {
509 const char*
str()
const {
return _str.c_str(); }
510 void str(
const char* newstr) {
_str = newstr; }
541 int nargs()
const {
return _nargs; }
544 double* scalarArgs()
const {
return &_scalarArgs[0]; }
545 Vec3d* vecArgs()
const {
return &_vecArgs[0]; }
548 Vec3d* evalArgs()
const;
551 Vec3d evalArg(
int n)
const;
563 bool isStrArg(
int n)
const {
return n < numChildren() && dynamic_cast<const ExprStrNode*>(
child(n)) != 0; }
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const char * name() const
bool checkIsFP(const ExprType &type, bool &error)
Checks if the type is a float[d] for any d.
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
const ExprPrototypeNode * prototype() const
TODO: Accessor for prototype (probably not needed when we use prep right)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
ExprType returnType() const
ExprNode * child(size_t i)
Get 0 indexed child.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
std::string getStrArg(int n) const
int numChildren() const
Number of children.
Node that implements a numeric/string comparison.
const ExprType & type() const
The type of the node.
Node that implements a numeric comparison.
void setTypeWithChildLife(const ExprType &t)
Set's the type to the argument but uses the children to determine lifetime.
short int length() const
Access length of input string.
void addError(const std::string &error) const
Register error. This will allow users and sophisticated editors to highlight where in code problem wa...
int buildInterpreter(Interpreter *interpreter) const
Build the interpreter.
ExprBinaryOpNode BinaryOp
ExprStrNode(const Expression *expr, const char *str)
const ExprFunc * func() const
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Node that stores a numeric constant.
std::vector< int > _promote
Node that implements an binary operator.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
Policy which provides all the AST Types for the parser.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprCompareEqNode CompareEq
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
void addFunc(const char *n) const
add function evaluation (this is for internal use)
unsigned short int _startPos
Position line and collumn.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprVarRef * var() const
const char * name() const
std::string toString() const
Access to original string representation of current expression.
ExprType & Constant()
Mutate this into a constant lifetime.
NOde that computes with a single operand.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprPrototypeNode Prototype
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprNumNode(const Expression *expr, double val)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
std::vector< int > _interpreterOps
ExprNode * _parent
Parent node (null if this the the root)
ExprIfThenElseNode IfThenElse
Node that calls a function.
char _op
_op '<' less-than, 'l' less-than-eq, '>' greater-than, 'g' greater-than-eq
ExprUnaryOpNode(const Expression *expr, ExprNode *a, char op)
Construct with specific op ('!x' is logical negation, '~x' is 1-x, '-x' is -x)
bool isVec() const
True if node has a vector result.
int interpreterOps(int c) const
Return op for interpreter.
bool checkIsFP(int d, const ExprType &type, bool &error)
Checks if the type is a float[d] for a specific d.
Function Definition, used in parse tree and func table.
Node that compute a local variable assignment.
Node that contains prototype of function.
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual ~ExprBinaryOpNode()
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Variable scope for tracking variable lookup.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
int buildInterpreterForCall(const ExprFuncNode *callerNode, Interpreter *interpreter) const
Build interpreter if we are called.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Node that contains entire program.
const ExprNode * arg(int i) const
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
ExprModuleNode(const Expression *expr)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprLocalVar * localVar() const
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
const std::string & name() const
const ExprLocalFunctionNode * _localFunc
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
const ExprNode * parent() const
Access parent node - root node has no parent.
Node that computes local variables before evaluating expression.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
bool _isVec
True if node has a vector result.
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
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
Node that constructs a vector from three scalars.
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.
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
ExprPrototypeNode(const Expression *expr, const std::string &name)
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.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
void str(const char *newstr)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
void setReturnType(const ExprType &type)
std::string toString() const
Stringify the type into a printable string.
ExprFuncNode(const Expression *expr, const char *name)
virtual void eval(ArgHandle args)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
Vec< double, 3, false > Vec3d
Data * getData() const
get associated blind data (returns 0 if none)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that evaluates a conditional (if-then-else) expression.
ExprType & setLifetime(const ExprType &a)
Assign the lifetime from type a to be my type.
const ExprType & assignedType() const
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
Node that stores a string.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprVarNode(const Expression *expr, const char *name)
base class for custom instance data
Node that evaluates a component of a vector.
const Expression * expr() const
Access expression.
Node that contains local function.
bool isStrArg(int n) const
int buildInterpreter(Interpreter *interpreter) const
Build the interpreter.
Node that computes local variables before evaluating expression.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
std::vector< ExprType > _argTypes
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
ExprVecNode(const Expression *expr)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
bool checkTypesCompatible(const ExprType &first, const ExprType &second, bool &error)
types match (true if they do)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
const ExprLocalVar * localVar() const
void addError(const std::string &error, const int startPos, const int endPos) const
abstract class for implementing variable references
const ExprNode * child(size_t i) const
Get 0 indexed child.
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])
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
bool isReturnTypeSet() const
short int startPos() const
Access start position in input string.
ExprLocalFunctionNode LocalFunction
ExprType argType(int i) const
unsigned short int _endPos
const Expression * _expr
Owning expression (node can't modify)
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
const std::string & name() const
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
void setType(const ExprType &t)
Set type of parameter.
void addArgTypes(ExprNode *surrogate)
void removeLastChild()
Remove last child and delete the entry.
ExprNode(const Expression *expr)
virtual ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder)
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
std::vector< ExprNode * > _children
List of children.