12 #include "ExprConfig.h"
110 return static_cast<int>(
_children.size());
200 for (
int i = 1; i < num; i++)
325 const std::string &
name()
const
427 const std::string &
name()
const
591 return _name.c_str();
643 void str(
const char *newstr)
680 return _name.c_str();
689 int nargs()
const {
return _nargs; }
692 double* scalarArgs()
const {
return &_scalarArgs[0]; }
693 Vec3d* vecArgs()
const {
return &_vecArgs[0]; }
696 Vec3d* evalArgs()
const;
699 Vec3d evalArg(
int n)
const;
713 return n < numChildren() && dynamic_cast<const ExprStrNode *>(
child(n)) !=
nullptr;
782 using Ptr = std::unique_ptr<Base *>;
void eval(ArgHandle args) override
Node that compute a local variable assignment.
const ExprLocalVar * localVar() const
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
const ExprType & assignedType() const
ExprAssignNode(const Expression *expr, const char *name, ExprNode *e)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const std::string & name() const
Node that implements an binary operator.
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprBinaryOpNode(const ExprBinaryOpNode &)=default
ExprBinaryOpNode & operator=(ExprBinaryOpNode &&)=default
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprBinaryOpNode & operator=(const ExprBinaryOpNode &)=default
ExprBinaryOpNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
~ExprBinaryOpNode() override
ExprBinaryOpNode(ExprBinaryOpNode &&)=default
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
Node that computes local variables before evaluating expression.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprBlockNode(const Expression *expr, ExprNode *a, ExprNode *b)
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that implements a numeric/string comparison.
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprCompareEqNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Node that implements a numeric comparison.
char _op
_op '<' less-than, 'l' less-than-eq, '>' greater-than, 'g' greater-than-eq
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprCompareNode(const Expression *expr, ExprNode *a, ExprNode *b, char op)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that evaluates a conditional (if-then-else) expression.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprCondNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
Node that calls a function.
bool isStrArg(int n) const
const ExprFunc * func() const
ExprFuncNode & operator=(const ExprFuncNode &)=default
bool checkArg(int argIndex, const ExprType &type, ExprVarEnvBuilder &envBuilder)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
void setData(Data *data) const
associate blind data with this node (subsequently owned by this object)
ExprFuncNode(const Expression *expr, const char *name)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
std::vector< int > _promote
ExprFuncNode(ExprFuncNode &&)=default
std::string getStrArg(int n) const
ExprFuncNode & operator=(ExprFuncNode &&)=default
const char * name() const
ExprFuncNode(const ExprFuncNode &)=default
Data * getData() const
get associated blind data (returns 0 if none)
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprLocalFunctionNode * _localFunc
Function Definition, used in parse tree and func table.
Node that computes local variables before evaluating expression.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprIfThenElseNode(const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Node that contains local function.
int buildInterpreter(Interpreter *interpreter) const override
Build the interpreter.
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)
ExprLocalFunctionNode(const Expression *expr, ExprPrototypeNode *prototype, ExprNode *block)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Preps the definition of this site.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprLocalVar reference, all local variables in seexpr are subclasses of this or this itself.
Node that contains entire program.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprModuleNode(const Expression *expr)
Policy which provides all the AST Types for the parser.
std::unique_ptr< Base * > Ptr
void addChildren(ExprNode *surrogate)
Transfer children from surrogate parent (for parser use only)
virtual LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BASE
void setPosition(const short int startPos, const short int endPos)
Remember the line and column position in the input string.
unsigned short int _startPos
Position line and collumn.
virtual ExprType prep(bool dontNeedScalar, ExprVarEnvBuilder &envBuilder)
void swapChildren(size_t i, size_t j)
Swap children, do not use unless you know what you are doing.
std::string toString() const
Access to original string representation of current expression.
const Expression * expr() const
Access expression.
unsigned short int endPos() const
Access end position in input string.
virtual int buildInterpreter(Interpreter *interpreter) const
builds an interpreter. Returns the location index for the evaluated data
bool _isVec
True if node has a vector result.
const ExprNode * parent() const
Access parent node - root node has no parent.
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.
unsigned short int startPos() const
Access start position in input string.
bool checkIsFP(int d, const ExprType &type, bool &error) const
Checks if the type is a float[d] for a specific d.
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.
void removeLastChild()
Remove last child and delete the entry.
unsigned short int _endPos
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)
ExprNode * child(size_t i)
Get 0 indexed child.
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.
bool isVec() const
True if node has a vector result.
void addChild(ExprNode *child)
Add a child to the child list (for parser use only)
unsigned short int length() const
Access length of input string.
Node that stores a numeric constant.
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprNumNode(const Expression *expr, double val)
Node that contains prototype of function.
std::vector< ExprType > _argTypes
void addArgs(ExprNode *surrogate)
ExprType returnType() const
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
int interpreterOps(int c) const
Return op for interpreter.
ExprPrototypeNode(const Expression *expr, const std::string &name)
const ExprNode * arg(int i) const
void setReturnType(const ExprType &type)
ExprType argType(int i) const
int buildInterpreter(Interpreter *interpreter) const override
Build the interpreter.
void addArgTypes(ExprNode *surrogate)
bool isReturnTypeSet() const
const std::string & name() const
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
std::vector< int > _interpreterOps
ExprPrototypeNode(const Expression *expr, const std::string &name, const ExprType &retType)
Node that stores a string.
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprStrNode(const Expression *expr, const char *str)
void str(const char *newstr)
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
Node that evaluates a component of a vector.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprSubscriptNode(const Expression *expr, ExprNode *a, ExprNode *b)
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
ExprType & Constant()
Mutate this into a constant lifetime.
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.
static bool valuesCompatible(const ExprType &a, const ExprType &b)
Checks if value types are compatible.
NOde that computes with a single operand.
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
ExprUnaryOpNode(const Expression *expr, ExprNode *a, char op)
Construct with specific op ('!x' is logical negation, '~x' is 1-x, '-x' is -x)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Variable scope for tracking variable lookup.
Node that references a variable.
const char * name() const
ExprVarNode(const Expression *expr, const char *name, const ExprType &type)
const ExprLocalVar * localVar() const
ExprVarNode(const Expression *expr, const char *name)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
const ExprVarRef * var() const
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
abstract class for implementing variable references
Node that constructs a vector from three scalars.
ExprType prep(bool wantScalar, ExprVarEnvBuilder &envBuilder) override
LLVM_VALUE codegen(LLVM_BUILDER) LLVM_BODY
ExprVecNode(const Expression *expr)
int buildInterpreter(Interpreter *interpreter) const override
builds an interpreter. Returns the location index for the evaluated data
const std::string & getExpr() const
Get the string that this expression is currently set to evaluate.
void addError(const ErrorCode error, const std::vector< std::string > ids, const int startPos, const int endPos) const
void addFunc(const char *n) const
add function evaluation (this is for internal use)
@ ExpectedStringOrFloatAnyD
"Expected String or Float[d]"
@ ExpectedFloatAnyD
"Expected Float[d]"
@ ExpectedFloatD
"Expected Float[" << d << "]"
@ TypeMismatch12
"Type mismatch. First: " << first << " Second: " << second
Vec< double, 3, false > Vec3d
base class for custom instance data
Data(const Data &)=default
Data & operator=(const Data &)=default
Data & operator=(Data &&)=default