SeExpr
|
#include <ExprNode.h>
Public Member Functions | |
ExprNode (const Expression *expr) | |
ExprNode (const Expression *expr, const ExprType &type) | |
virtual | ~ExprNode () |
virtual LLVM_VALUE | codegen (LLVM_BUILDER) LLVM_BODY |
bool | isVec () const |
True if node has a vector result. More... | |
const Expression * | expr () const |
Access expression. More... | |
std::string | toString () const |
Access to original string representation of current expression. More... | |
const ExprType & | type () const |
The type of the node. More... | |
void | addError (const std::string &error) const |
Register error. This will allow users and sophisticated editors to highlight where in code problem was. More... | |
These constructors supply one or more children. | |
ExprNode (const Expression *expr, ExprNode *a) | |
ExprNode (const Expression *expr, ExprNode *a, const ExprType &type) | |
ExprNode (const Expression *expr, ExprNode *a, ExprNode *b) | |
ExprNode (const Expression *expr, ExprNode *a, ExprNode *b, const ExprType &type) | |
ExprNode (const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c) | |
ExprNode (const Expression *expr, ExprNode *a, ExprNode *b, ExprNode *c, const ExprType &type) | |
Interface to implement for subclasses | |
virtual ExprType | prep (bool dontNeedScalar, ExprVarEnvBuilder &envBuilder) |
virtual int | buildInterpreter (Interpreter *interpreter) const |
builds an interpreter. Returns the location index for the evaluated data More... | |
Relationship Queries and Manipulation | |
const ExprNode * | parent () const |
Access parent node - root node has no parent. More... | |
int | numChildren () const |
Number of children. More... | |
const ExprNode * | child (size_t i) const |
Get 0 indexed child. More... | |
ExprNode * | child (size_t i) |
Get 0 indexed child. More... | |
void | swapChildren (size_t i, size_t j) |
Swap children, do not use unless you know what you are doing. More... | |
void | removeLastChild () |
Remove last child and delete the entry. More... | |
void | addChild (ExprNode *child) |
Add a child to the child list (for parser use only) More... | |
void | addChildren (ExprNode *surrogate) |
Transfer children from surrogate parent (for parser use only) More... | |
Access position in the input buffer that created this node | |
void | setPosition (const short int startPos, const short int endPos) |
Remember the line and column position in the input string. More... | |
short int | startPos () const |
Access start position in input string. More... | |
short int | endPos () const |
Access end position in input string. More... | |
short int | length () const |
Access length of input string. More... | |
Error Checking Helpers for Type Checking | |
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. More... | |
bool | checkIsValue (const ExprType &type, bool &error) |
Checks if the type is a value (i.e. string or float[d]) More... | |
bool | checkIsFP (const ExprType &type, bool &error) |
Checks if the type is a float[d] for any d. More... | |
bool | checkIsFP (int d, const ExprType &type, bool &error) |
Checks if the type is a float[d] for a specific d. More... | |
bool | checkTypesCompatible (const ExprType &first, const ExprType &second, bool &error) |
types match (true if they do) More... | |
Protected Member Functions | |
void | setType (const ExprType &t) |
Set type of parameter. More... | |
void | setTypeWithChildLife (const ExprType &t) |
Set's the type to the argument but uses the children to determine lifetime. More... | |
Protected Attributes | |
const Expression * | _expr |
Owning expression (node can't modify) More... | |
ExprNode * | _parent |
Parent node (null if this the the root) More... | |
std::vector< ExprNode * > | _children |
List of children. More... | |
bool | _isVec |
True if node has a vector result. More... | |
ExprType | _type |
int | _maxChildDim |
unsigned short int | _startPos |
Position line and collumn. More... | |
unsigned short int | _endPos |
Expression node base class. Always constructed by parser in ExprParser.y Parse tree nodes - this is where the expression evaluation happens.
Some implementation notes:
1) Vector vs scalar - Any node can accept vector or scalar inputs and return a vector or scalar result. If a node returns a scalar, it is only required to set the [0] component and the other components must be assumed to be invalid.
2) ExprNode::prep - This is called for all nodes during parsing once the syntax has been checked. Anything can be done here, such as function binding, variable lookups, etc., but the only thing that must be done is to determine whether the result is going to be vector or scalar. This can in some cases depend on whether the children are vector or scalar so the parser calls prep on the root node and each node is expected to call prep on its children and then set its own _isVec variable. The wantVec param provides context from the parent (and ultimately the owning expression) as to whether a vector is desired, but nodes are not bound by this and may produce a scalar even when a vector is wanted.
The base class method implements the default behavior which is to pass down the wantVec flag to all children and set isVec to true if any child is a vec.
If the prep method fails, an error string should be set and false should be returned.
Definition at line 72 of file ExprNode.h.
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr | ) |
Definition at line 39 of file ExprNode.cpp.
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
const ExprType & | type | ||
) |
Definition at line 41 of file ExprNode.cpp.
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a | ||
) |
Definition at line 43 of file ExprNode.cpp.
References _children, and addChild().
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
const ExprType & | type | ||
) |
Definition at line 48 of file ExprNode.cpp.
References _children, and addChild().
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b | ||
) |
Definition at line 54 of file ExprNode.cpp.
References _children, and addChild().
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
const ExprType & | type | ||
) |
Definition at line 60 of file ExprNode.cpp.
References _children, and addChild().
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
ExprNode * | c | ||
) |
Definition at line 67 of file ExprNode.cpp.
References _children, and addChild().
SeExpr2::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
ExprNode * | c, | ||
const ExprType & | type | ||
) |
Definition at line 74 of file ExprNode.cpp.
References _children, and addChild().
|
virtual |
Definition at line 82 of file ExprNode.cpp.
References _children.
void SeExpr2::ExprNode::addChild | ( | ExprNode * | child | ) |
Add a child to the child list (for parser use only)
Definition at line 88 of file ExprNode.cpp.
References _children, and _parent.
Referenced by addChildren(), ExprNode(), and SeExpr2::GetVar::prep().
void SeExpr2::ExprNode::addChildren | ( | ExprNode * | surrogate | ) |
Transfer children from surrogate parent (for parser use only)
Definition at line 93 of file ExprNode.cpp.
References _children, and addChild().
Referenced by SeExpr2::ExprPrototypeNode::addArgs(), and SeExpr2::ExprPrototypeNode::addArgTypes().
|
inline |
Register error. This will allow users and sophisticated editors to highlight where in code problem was.
Definition at line 168 of file ExprNode.h.
References _endPos, _expr, _startPos, and SeExpr2::Expression::addError().
Referenced by SeExpr2::ExprFuncNode::checkArg(), checkCondition(), SeExpr2::Expression::prep(), SeExpr2::ExprVarNode::prep(), SeExpr2::CachedVoronoiFunc::prep(), SeExpr2::CurveFuncX::prep(), SeExpr2::CCurveFuncX::prep(), and SeExpr2::PrintFuncX::prep().
|
virtual |
builds an interpreter. Returns the location index for the evaluated data
Reimplemented in SeExpr2::ExprFuncNode, SeExpr2::ExprStrNode, SeExpr2::ExprNumNode, SeExpr2::ExprVarNode, SeExpr2::ExprBinaryOpNode, SeExpr2::ExprCompareNode, SeExpr2::ExprCompareEqNode, SeExpr2::ExprSubscriptNode, SeExpr2::ExprCondNode, SeExpr2::ExprUnaryOpNode, SeExpr2::ExprVecNode, SeExpr2::ExprAssignNode, SeExpr2::ExprIfThenElseNode, SeExpr2::ExprBlockNode, SeExpr2::ExprLocalFunctionNode, SeExpr2::ExprPrototypeNode, and SeExpr2::ExprModuleNode.
Definition at line 477 of file Interpreter.cpp.
References buildInterpreter(), child(), and numChildren().
Referenced by buildInterpreter(), SeExpr2::ExprFuncSimple::buildInterpreter(), SeExpr2::ExprFuncStandard::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreter(), SeExpr2::ExprIfThenElseNode::buildInterpreter(), SeExpr2::ExprAssignNode::buildInterpreter(), SeExpr2::ExprVecNode::buildInterpreter(), SeExpr2::ExprUnaryOpNode::buildInterpreter(), SeExpr2::ExprSubscriptNode::buildInterpreter(), SeExpr2::ExprCompareNode::buildInterpreter(), SeExpr2::ExprBinaryOpNode::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreterForCall(), and SeExpr2::Expression::prep().
|
inline |
Checks the boolean value and records an error string with node if it is false.
Definition at line 190 of file ExprNode.h.
References addError().
Referenced by checkIsFP(), checkIsValue(), checkTypesCompatible(), SeExpr2::ExprFuncStandard::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprLocalFunctionNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprVarNode::prep(), and SeExpr2::ExprFuncNode::prep().
|
inline |
Checks if the type is a float[d] for any d.
Definition at line 202 of file ExprNode.h.
References checkCondition(), and SeExpr2::ExprType::isFP().
Referenced by SeExpr2::ExprFuncStandard::prep(), SeExpr2::ExprIfThenElseNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprUnaryOpNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprSubscriptNode::prep(), SeExpr2::ExprCompareNode::prep(), and SeExpr2::ExprBinaryOpNode::prep().
|
inline |
Checks if the type is a float[d] for a specific d.
Definition at line 206 of file ExprNode.h.
References checkCondition(), and SeExpr2::ExprType::isFP().
|
inline |
Checks if the type is a value (i.e. string or float[d])
Definition at line 198 of file ExprNode.h.
References checkCondition(), and SeExpr2::ExprType::isValue().
Referenced by SeExpr2::ExprCondNode::prep(), and SeExpr2::ExprCompareEqNode::prep().
|
inline |
types match (true if they do)
Definition at line 215 of file ExprNode.h.
References checkCondition(), SeExpr2::ExprType::toString(), and SeExpr2::ExprType::valuesCompatible().
Referenced by SeExpr2::ExprCompareEqNode::prep(), SeExpr2::ExprCompareNode::prep(), and SeExpr2::ExprBinaryOpNode::prep().
|
inline |
Get 0 indexed child.
Definition at line 117 of file ExprNode.h.
References _children.
Referenced by SeExpr2::ExprPrototypeNode::addArgs(), SeExpr2::ExprPrototypeNode::addArgTypes(), SeExpr2::ExprPrototypeNode::arg(), buildInterpreter(), SeExpr2::ExprFuncSimple::buildInterpreter(), SeExpr2::ExprFuncStandard::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreter(), SeExpr2::ExprIfThenElseNode::buildInterpreter(), SeExpr2::ExprAssignNode::buildInterpreter(), SeExpr2::ExprVecNode::buildInterpreter(), SeExpr2::ExprUnaryOpNode::buildInterpreter(), SeExpr2::ExprSubscriptNode::buildInterpreter(), SeExpr2::ExprCompareNode::buildInterpreter(), SeExpr2::ExprBinaryOpNode::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreterForCall(), SeExpr2::ExprFuncNode::checkArg(), SeExpr2::ExprCurveAssignSpec< T >::ExprCurveAssignSpec(), SeExpr2::ExprFuncNode::getStrArg(), SeExpr2::ExprFuncNode::isStrArg(), SeExpr2::isStrFunc(), prep(), SeExpr2::ExprFuncStandard::prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprLocalFunctionNode::prep(), SeExpr2::ExprBlockNode::prep(), SeExpr2::ExprIfThenElseNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprUnaryOpNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprSubscriptNode::prep(), SeExpr2::ExprCompareEqNode::prep(), SeExpr2::ExprCompareNode::prep(), SeExpr2::ExprBinaryOpNode::prep(), SeExpr2::GetVar::prep(), SeExpr2::ExprLocalFunctionNode::prototype(), setTypeWithChildLife(), SeExpr2::ExprVecNode::value(), and SeExpr2::Walker< constnode >::walkChildren().
|
inline |
|
virtual |
Reimplemented in SeExpr2::ExprFuncNode, SeExpr2::ExprStrNode, SeExpr2::ExprNumNode, SeExpr2::ExprVarNode, SeExpr2::ExprBinaryOpNode, SeExpr2::ExprCompareNode, SeExpr2::ExprCompareEqNode, SeExpr2::ExprSubscriptNode, SeExpr2::ExprCondNode, SeExpr2::ExprUnaryOpNode, SeExpr2::ExprVecNode, SeExpr2::ExprAssignNode, SeExpr2::ExprIfThenElseNode, SeExpr2::ExprBlockNode, SeExpr2::ExprLocalFunctionNode, SeExpr2::ExprPrototypeNode, and SeExpr2::ExprModuleNode.
|
inline |
Access end position in input string.
Definition at line 159 of file ExprNode.h.
References _endPos.
Referenced by SeExpr2::findComment(), length(), and setPosition().
|
inline |
Access expression.
Definition at line 102 of file ExprNode.h.
References _expr.
Referenced by SeExpr2::findComment(), SeExpr2::GetVar::prep(), and toString().
|
inline |
True if node has a vector result.
Definition at line 99 of file ExprNode.h.
References _isVec.
Referenced by SeExpr2::Expression::isVec().
|
inline |
Access length of input string.
Definition at line 161 of file ExprNode.h.
References endPos(), and startPos().
Referenced by toString().
|
inline |
Number of children.
Definition at line 114 of file ExprNode.h.
References _children.
Referenced by SeExpr2::ExprPrototypeNode::addArgs(), SeExpr2::ExprPrototypeNode::addArgTypes(), buildInterpreter(), SeExpr2::ExprFuncSimple::buildInterpreter(), SeExpr2::ExprFuncStandard::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreter(), SeExpr2::ExprVecNode::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreterForCall(), SeExpr2::ExprCurveAssignSpec< T >::ExprCurveAssignSpec(), SeExpr2::ExprFuncNode::getStrArg(), SeExpr2::hasCurveNumArgs(), SeExpr2::isCcurveFunc(), SeExpr2::isCurveFunc(), SeExpr2::isStrFunc(), SeExpr2::RandFuncX::prep(), BasicExpression::DummyFuncX::prep(), SeExpr2::MapFuncX::prep(), prep(), SeExpr2::TriplanarFuncX::prep(), SeExpr2::ExprFuncStandard::prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprLocalFunctionNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprFuncNode::prep(), SeExpr2::CachedVoronoiFunc::prep(), SeExpr2::CurveFuncX::prep(), SeExpr2::CCurveFuncX::prep(), SeExpr2::PrintFuncX::prep(), setTypeWithChildLife(), and SeExpr2::Walker< constnode >::walkChildren().
|
inline |
Access parent node - root node has no parent.
Definition at line 112 of file ExprNode.h.
References _parent.
Referenced by SeExpr2::TypePrintExaminer::examine().
|
virtual |
Prepare the node (for parser use only). See the discussion at the start of SeExprNode.cpp for more info.
Default is to call prep on children (giving AnyType as desired type). If all children return valid types, returns NoneType. Otherwise, returns ErrorType. Note: Ignores wanted type.
Reimplemented in SeExpr2::ExprFuncNode, SeExpr2::ExprStrNode, SeExpr2::ExprNumNode, SeExpr2::ExprVarNode, SeExpr2::ExprBinaryOpNode, SeExpr2::ExprCompareNode, SeExpr2::ExprCompareEqNode, SeExpr2::ExprSubscriptNode, SeExpr2::ExprCondNode, SeExpr2::ExprUnaryOpNode, SeExpr2::ExprVecNode, SeExpr2::ExprAssignNode, SeExpr2::ExprIfThenElseNode, SeExpr2::ExprBlockNode, SeExpr2::ExprLocalFunctionNode, SeExpr2::ExprPrototypeNode, and SeExpr2::ExprModuleNode.
Definition at line 102 of file ExprNode.cpp.
References _maxChildDim, _type, child(), SeExpr2::ExprType::dim(), SeExpr2::ExprType::isFP(), SeExpr2::ExprType::isValid(), numChildren(), prep(), setType(), setTypeWithChildLife(), and type().
Referenced by SeExpr2::ExprFuncNode::checkArg(), prep(), SeExpr2::ExprFuncStandard::prep(), SeExpr2::Expression::prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprLocalFunctionNode::prep(), SeExpr2::ExprBlockNode::prep(), SeExpr2::ExprIfThenElseNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprUnaryOpNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprSubscriptNode::prep(), SeExpr2::ExprCompareEqNode::prep(), SeExpr2::ExprCompareNode::prep(), SeExpr2::ExprBinaryOpNode::prep(), SeExpr2::ExprFuncNode::prep(), and SeExpr2::GetVar::prep().
|
inline |
Remove last child and delete the entry.
Definition at line 129 of file ExprNode.h.
References _children.
Referenced by SeExpr2::GetVar::prep().
|
inline |
Remember the line and column position in the input string.
Definition at line 152 of file ExprNode.h.
References _endPos, _startPos, endPos(), and startPos().
|
inlineprotected |
Set type of parameter.
Definition at line 172 of file ExprNode.h.
References _type.
Referenced by prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprBlockNode::prep(), SeExpr2::ExprIfThenElseNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprUnaryOpNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprSubscriptNode::prep(), SeExpr2::ExprCompareEqNode::prep(), SeExpr2::ExprCompareNode::prep(), SeExpr2::ExprBinaryOpNode::prep(), SeExpr2::ExprVarNode::prep(), and setTypeWithChildLife().
|
inlineprotected |
Set's the type to the argument but uses the children to determine lifetime.
Definition at line 176 of file ExprNode.h.
References _type, child(), SeExpr2::ExprType::Constant(), numChildren(), SeExpr2::ExprType::setLifetime(), setType(), and type().
Referenced by prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprVecNode::prep(), and SeExpr2::ExprFuncNode::prep().
|
inline |
Access start position in input string.
Definition at line 157 of file ExprNode.h.
References _startPos.
Referenced by length(), setPosition(), and toString().
|
inline |
Swap children, do not use unless you know what you are doing.
Definition at line 123 of file ExprNode.h.
References _children.
Referenced by SeExpr2::GetVar::prep().
|
inline |
Access to original string representation of current expression.
Definition at line 105 of file ExprNode.h.
References expr(), SeExpr2::Expression::getExpr(), length(), and startPos().
Referenced by SeExpr2::TypePrintExaminer::examine(), and SeExpr2::ExprCurveAssignSpec< T >::ExprCurveAssignSpec().
|
inline |
The type of the node.
Definition at line 145 of file ExprNode.h.
References _type.
Referenced by SeExpr2::ExprPrototypeNode::addArgs(), SeExpr2::ExprPrototypeNode::addArgTypes(), SeExpr2::ExprFuncSimple::buildInterpreter(), SeExpr2::ExprFuncStandard::buildInterpreter(), SeExpr2::ExprAssignNode::buildInterpreter(), SeExpr2::ExprUnaryOpNode::buildInterpreter(), SeExpr2::ExprSubscriptNode::buildInterpreter(), SeExpr2::ExprCompareNode::buildInterpreter(), SeExpr2::ExprBinaryOpNode::buildInterpreter(), SeExpr2::ExprVarNode::buildInterpreter(), SeExpr2::ExprLocalFunctionNode::buildInterpreterForCall(), SeExpr2::Expression::debugPrintParseTree(), SeExpr2::GetVar::evalConstant(), SeExpr2::TypePrintExaminer::examine(), prep(), SeExpr2::Expression::prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprFuncNode::prep(), SeExpr2::ExprPrototypeNode::setReturnType(), and setTypeWithChildLife().
|
protected |
List of children.
Definition at line 231 of file ExprNode.h.
Referenced by addChild(), addChildren(), child(), ExprNode(), numChildren(), removeLastChild(), swapChildren(), and ~ExprNode().
|
protected |
Definition at line 241 of file ExprNode.h.
Referenced by addError(), endPos(), and setPosition().
|
protected |
Owning expression (node can't modify)
Definition at line 225 of file ExprNode.h.
Referenced by addError(), expr(), SeExpr2::ExprVarNode::prep(), and SeExpr2::ExprFuncNode::prep().
|
protected |
|
protected |
Definition at line 238 of file ExprNode.h.
Referenced by prep().
|
protected |
Parent node (null if this the the root)
Definition at line 228 of file ExprNode.h.
Referenced by addChild(), and parent().
|
protected |
Position line and collumn.
Definition at line 241 of file ExprNode.h.
Referenced by addError(), setPosition(), and startPos().
|
protected |
Definition at line 237 of file ExprNode.h.
Referenced by prep(), SeExpr2::ExprModuleNode::prep(), SeExpr2::ExprPrototypeNode::prep(), SeExpr2::ExprLocalFunctionNode::prep(), SeExpr2::ExprBlockNode::prep(), SeExpr2::ExprIfThenElseNode::prep(), SeExpr2::ExprAssignNode::prep(), SeExpr2::ExprVecNode::prep(), SeExpr2::ExprUnaryOpNode::prep(), SeExpr2::ExprCondNode::prep(), SeExpr2::ExprSubscriptNode::prep(), SeExpr2::ExprCompareEqNode::prep(), SeExpr2::ExprCompareNode::prep(), SeExpr2::ExprBinaryOpNode::prep(), SeExpr2::ExprVarNode::prep(), SeExpr2::ExprNumNode::prep(), SeExpr2::ExprStrNode::prep(), SeExpr2::ExprFuncNode::prep(), setType(), setTypeWithChildLife(), and type().