KSeExpr 6.0.0.0
|
#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_BASE |
bool | isVec () const |
True if node has a vector result. | |
const Expression * | expr () const |
Access expression. | |
std::string | toString () const |
Access to original string representation of current expression. | |
const ExprType & | type () const |
The type of the node. | |
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 was. | |
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 | |
Relationship Queries and Manipulation | |
const ExprNode * | parent () const |
Access parent node - root node has no parent. | |
int | numChildren () const |
Number of children. | |
const ExprNode * | child (size_t i) const |
Get 0 indexed child. | |
ExprNode * | child (size_t i) |
Get 0 indexed child. | |
void | swapChildren (size_t i, size_t j) |
Swap children, do not use unless you know what you are doing. | |
void | removeLastChild () |
Remove last child and delete the entry. | |
void | addChild (ExprNode *child) |
Add a child to the child list (for parser use only) | |
void | addChildren (ExprNode *surrogate) |
Transfer children from surrogate parent (for parser use only) | |
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. | |
unsigned short int | startPos () const |
Access start position in input string. | |
unsigned short int | endPos () const |
Access end position in input string. | |
unsigned short int | length () const |
Access length of input string. | |
Error Checking Helpers for Type Checking | |
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. | |
bool | checkIsValue (const ExprType &type, bool &error) const |
Checks if the type is a value (i.e. string or float[d]) | |
bool | checkIsFP (const ExprType &type, bool &error) const |
Checks if the type is a float[d] for any d. | |
bool | checkIsFP (int d, const ExprType &type, bool &error) const |
Checks if the type is a float[d] for a specific d. | |
bool | checkTypesCompatible (const ExprType &first, const ExprType &second, bool &error) const |
types match (true if they do) | |
Protected Member Functions | |
void | setType (const ExprType &t) |
Set type of parameter. | |
void | setTypeWithChildLife (const ExprType &t) |
Set's the type to the argument but uses the children to determine lifetime. | |
Protected Attributes | |
const Expression * | _expr {nullptr} |
Owning expression (node can't modify) | |
ExprNode * | _parent {nullptr} |
Parent node (null if this the the root) | |
std::vector< ExprNode * > | _children |
List of children. | |
bool | _isVec |
True if node has a vector result. | |
ExprType | _type |
int | _maxChildDim {} |
unsigned short int | _startPos {} |
Position line and collumn. | |
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 55 of file ExprNode.h.
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr | ) |
Definition at line 28 of file ExprNode.cpp.
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
const ExprType & | type | ||
) |
Definition at line 34 of file ExprNode.cpp.
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a | ||
) |
Definition at line 41 of file ExprNode.cpp.
References _children, and addChild().
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
const ExprType & | type | ||
) |
Definition at line 49 of file ExprNode.cpp.
References _children, and addChild().
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b | ||
) |
Definition at line 58 of file ExprNode.cpp.
References _children, and addChild().
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
const ExprType & | type | ||
) |
Definition at line 67 of file ExprNode.cpp.
References _children, and addChild().
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
ExprNode * | c | ||
) |
Definition at line 77 of file ExprNode.cpp.
References _children, and addChild().
KSeExpr::ExprNode::ExprNode | ( | const Expression * | expr, |
ExprNode * | a, | ||
ExprNode * | b, | ||
ExprNode * | c, | ||
const ExprType & | type | ||
) |
Definition at line 87 of file ExprNode.cpp.
References _children, and addChild().
|
virtual |
Definition at line 98 of file ExprNode.cpp.
References _children.
Add a child to the child list (for parser use only)
Definition at line 106 of file ExprNode.cpp.
References _children, and child().
Referenced by addChildren(), ExprNode(), ExprNode(), ExprNode(), ExprNode(), ExprNode(), and ExprNode().
Transfer children from surrogate parent (for parser use only)
Definition at line 112 of file ExprNode.cpp.
References addChild().
Referenced by KSeExpr::ExprPrototypeNode::addArgs(), and KSeExpr::ExprPrototypeNode::addArgTypes().
|
inline |
Register error. This will allow users and sophisticated editors to highlight where in code problem was.
Definition at line 182 of file ExprNode.h.
Referenced by checkCondition(), KSeExpr::Expression::prep(), and KSeExpr::ExprVarNode::prep().
|
virtual |
builds an interpreter. Returns the location index for the evaluated data
Reimplemented in KSeExpr::ExprModuleNode, KSeExpr::ExprPrototypeNode, KSeExpr::ExprLocalFunctionNode, KSeExpr::ExprBlockNode, KSeExpr::ExprIfThenElseNode, KSeExpr::ExprAssignNode, KSeExpr::ExprVecNode, KSeExpr::ExprUnaryOpNode, KSeExpr::ExprCondNode, KSeExpr::ExprSubscriptNode, KSeExpr::ExprCompareEqNode, KSeExpr::ExprCompareNode, KSeExpr::ExprBinaryOpNode, KSeExpr::ExprVarNode, KSeExpr::ExprNumNode, KSeExpr::ExprStrNode, and KSeExpr::ExprFuncNode.
Definition at line 530 of file Interpreter.cpp.
References child(), and numChildren().
Referenced by KSeExpr::ExprVecNode::buildInterpreter(), and KSeExpr::Expression::prep().
|
inline |
Checks the boolean value and records an error string with node if it is false.
Definition at line 210 of file ExprNode.h.
References addError().
Referenced by checkIsFP(), checkIsFP(), checkIsValue(), checkTypesCompatible(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprLocalFunctionNode::prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprCondNode::prep(), KSeExpr::ExprVarNode::prep(), and KSeExpr::ExprFuncNode::prep().
Checks if the type is a float[d] for any d.
Definition at line 224 of file ExprNode.h.
References checkCondition(), KSeExpr::ExpectedFloatAnyD, and type().
Referenced by KSeExpr::ExprIfThenElseNode::prep(), KSeExpr::ExprVecNode::prep(), KSeExpr::ExprUnaryOpNode::prep(), KSeExpr::ExprCondNode::prep(), KSeExpr::ExprSubscriptNode::prep(), and KSeExpr::ExprCompareNode::prep().
Checks if the type is a float[d] for a specific d.
Definition at line 229 of file ExprNode.h.
References checkCondition(), KSeExpr::ExpectedFloatD, and type().
Checks if the type is a value (i.e. string or float[d])
Definition at line 219 of file ExprNode.h.
References checkCondition(), KSeExpr::ExpectedStringOrFloatAnyD, and type().
Referenced by KSeExpr::ExprCondNode::prep(), and KSeExpr::ExprCompareEqNode::prep().
|
inline |
types match (true if they do)
Definition at line 234 of file ExprNode.h.
References checkCondition(), KSeExpr::TypeMismatch12, and KSeExpr::ExprType::valuesCompatible().
Referenced by KSeExpr::ExprCompareEqNode::prep(), KSeExpr::ExprCompareNode::prep(), and KSeExpr::ExprBinaryOpNode::prep().
Get 0 indexed child.
Definition at line 114 of file ExprNode.h.
References _children.
Referenced by KSeExpr::ExprPrototypeNode::addArgs(), KSeExpr::ExprPrototypeNode::addArgTypes(), addChild(), KSeExpr::ExprPrototypeNode::arg(), buildInterpreter(), KSeExpr::ExprModuleNode::buildInterpreter(), KSeExpr::ExprPrototypeNode::buildInterpreter(), KSeExpr::ExprLocalFunctionNode::buildInterpreter(), KSeExpr::ExprBlockNode::buildInterpreter(), KSeExpr::ExprIfThenElseNode::buildInterpreter(), KSeExpr::ExprAssignNode::buildInterpreter(), KSeExpr::ExprVecNode::buildInterpreter(), KSeExpr::ExprUnaryOpNode::buildInterpreter(), KSeExpr::ExprCondNode::buildInterpreter(), KSeExpr::ExprSubscriptNode::buildInterpreter(), KSeExpr::ExprCompareEqNode::buildInterpreter(), KSeExpr::ExprCompareNode::buildInterpreter(), KSeExpr::ExprBinaryOpNode::buildInterpreter(), KSeExpr::ExprLocalFunctionNode::buildInterpreterForCall(), KSeExpr::ExprFuncNode::checkArg(), KSeExpr::ExprFuncNode::getStrArg(), KSeExpr::ExprFuncNode::isStrArg(), prep(), KSeExpr::ExprModuleNode::prep(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprLocalFunctionNode::prep(), KSeExpr::ExprBlockNode::prep(), KSeExpr::ExprIfThenElseNode::prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprVecNode::prep(), KSeExpr::ExprUnaryOpNode::prep(), KSeExpr::ExprCondNode::prep(), KSeExpr::ExprSubscriptNode::prep(), KSeExpr::ExprCompareEqNode::prep(), KSeExpr::ExprCompareNode::prep(), KSeExpr::ExprBinaryOpNode::prep(), KSeExpr::ExprLocalFunctionNode::prototype(), setTypeWithChildLife(), and KSeExpr::ExprVecNode::value().
|
virtual |
Reimplemented in KSeExpr::ExprModuleNode, KSeExpr::ExprPrototypeNode, KSeExpr::ExprLocalFunctionNode, KSeExpr::ExprBlockNode, KSeExpr::ExprIfThenElseNode, KSeExpr::ExprAssignNode, KSeExpr::ExprVecNode, KSeExpr::ExprUnaryOpNode, KSeExpr::ExprCondNode, KSeExpr::ExprSubscriptNode, KSeExpr::ExprCompareEqNode, KSeExpr::ExprCompareNode, KSeExpr::ExprBinaryOpNode, KSeExpr::ExprVarNode, KSeExpr::ExprNumNode, KSeExpr::ExprStrNode, and KSeExpr::ExprFuncNode.
Access end position in input string.
Definition at line 169 of file ExprNode.h.
References _endPos.
Referenced by length(), and setPosition().
|
inline |
Access expression.
Definition at line 89 of file ExprNode.h.
References _expr.
Referenced by KSeExpr::ExprFuncNode::ExprFuncNode(), and toString().
|
inline |
True if node has a vector result.
Definition at line 83 of file ExprNode.h.
References _isVec.
Referenced by KSeExpr::Expression::isVec().
Access length of input string.
Definition at line 174 of file ExprNode.h.
References endPos(), and startPos().
Referenced by toString().
|
inline |
Number of children.
Definition at line 108 of file ExprNode.h.
References _children.
Referenced by KSeExpr::ExprPrototypeNode::addArgs(), KSeExpr::ExprPrototypeNode::addArgTypes(), buildInterpreter(), KSeExpr::ExprModuleNode::buildInterpreter(), KSeExpr::ExprPrototypeNode::buildInterpreter(), KSeExpr::ExprLocalFunctionNode::buildInterpreter(), KSeExpr::ExprBlockNode::buildInterpreter(), KSeExpr::ExprVecNode::buildInterpreter(), KSeExpr::ExprFuncNode::getStrArg(), prep(), KSeExpr::ExprModuleNode::prep(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprVecNode::prep(), KSeExpr::ExprFuncNode::prep(), KSeExpr::ExprLocalFunctionNode::prep(), BasicExpression::DummyFuncX::prep(), and setTypeWithChildLife().
Access parent node - root node has no parent.
Definition at line 103 of file ExprNode.h.
References _parent.
|
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 KSeExpr::ExprModuleNode, KSeExpr::ExprPrototypeNode, KSeExpr::ExprLocalFunctionNode, KSeExpr::ExprBlockNode, KSeExpr::ExprIfThenElseNode, KSeExpr::ExprAssignNode, KSeExpr::ExprVecNode, KSeExpr::ExprUnaryOpNode, KSeExpr::ExprCondNode, KSeExpr::ExprSubscriptNode, KSeExpr::ExprCompareEqNode, KSeExpr::ExprCompareNode, KSeExpr::ExprBinaryOpNode, KSeExpr::ExprVarNode, KSeExpr::ExprNumNode, KSeExpr::ExprStrNode, and KSeExpr::ExprFuncNode.
Definition at line 121 of file ExprNode.cpp.
References _maxChildDim, _type, child(), KSeExpr::None, numChildren(), setType(), and setTypeWithChildLife().
Referenced by KSeExpr::Expression::prep(), and KSeExpr::ExprFuncNode::prep().
|
inline |
Remove last child and delete the entry.
Definition at line 133 of file ExprNode.h.
References _children.
Remember the line and column position in the input string.
Definition at line 158 of file ExprNode.h.
References _endPos, _startPos, endPos(), and startPos().
Set type of parameter.
Definition at line 189 of file ExprNode.h.
References _type.
Referenced by prep(), KSeExpr::ExprModuleNode::prep(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprLocalFunctionNode::prep(), KSeExpr::ExprBlockNode::prep(), KSeExpr::ExprIfThenElseNode::prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprVecNode::prep(), KSeExpr::ExprUnaryOpNode::prep(), KSeExpr::ExprCondNode::prep(), KSeExpr::ExprSubscriptNode::prep(), KSeExpr::ExprCompareEqNode::prep(), KSeExpr::ExprCompareNode::prep(), KSeExpr::ExprBinaryOpNode::prep(), KSeExpr::ExprVarNode::prep(), and setTypeWithChildLife().
Set's the type to the argument but uses the children to determine lifetime.
Definition at line 194 of file ExprNode.h.
References _type, child(), KSeExpr::ExprType::Constant(), numChildren(), KSeExpr::ExprType::setLifetime(), setType(), and type().
Referenced by prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprVecNode::prep(), and KSeExpr::ExprFuncNode::prep().
Access start position in input string.
Definition at line 164 of file ExprNode.h.
References _startPos.
Referenced by length(), setPosition(), and toString().
Swap children, do not use unless you know what you are doing.
Definition at line 126 of file ExprNode.h.
References _children.
|
inline |
Access to original string representation of current expression.
Definition at line 95 of file ExprNode.h.
References expr(), length(), and startPos().
The type of the node.
Definition at line 150 of file ExprNode.h.
References _type.
Referenced by KSeExpr::ExprPrototypeNode::addArgs(), KSeExpr::ExprUnaryOpNode::buildInterpreter(), KSeExpr::ExprCondNode::buildInterpreter(), KSeExpr::ExprCompareNode::buildInterpreter(), KSeExpr::ExprBinaryOpNode::buildInterpreter(), KSeExpr::ExprVarNode::buildInterpreter(), KSeExpr::ExprFuncNode::checkArg(), checkIsFP(), checkIsFP(), checkIsValue(), KSeExpr::Expression::debugPrintParseTree(), KSeExpr::Expression::prep(), KSeExpr::ExprModuleNode::prep(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprFuncNode::prep(), KSeExpr::ExprPrototypeNode::setReturnType(), and setTypeWithChildLife().
|
protected |
List of children.
Definition at line 247 of file ExprNode.h.
Referenced by addChild(), child(), child(), ExprNode(), ExprNode(), ExprNode(), ExprNode(), ExprNode(), ExprNode(), numChildren(), removeLastChild(), swapChildren(), and ~ExprNode().
Definition at line 257 of file ExprNode.h.
Referenced by endPos(), and setPosition().
|
protected |
Owning expression (node can't modify)
Definition at line 241 of file ExprNode.h.
Referenced by expr(), KSeExpr::ExprVarNode::prep(), and KSeExpr::ExprFuncNode::prep().
|
protected |
|
protected |
Definition at line 254 of file ExprNode.h.
Referenced by prep().
Parent node (null if this the the root)
Definition at line 244 of file ExprNode.h.
Referenced by parent().
Position line and collumn.
Definition at line 257 of file ExprNode.h.
Referenced by setPosition(), and startPos().
|
protected |
Definition at line 253 of file ExprNode.h.
Referenced by prep(), KSeExpr::ExprModuleNode::prep(), KSeExpr::ExprPrototypeNode::prep(), KSeExpr::ExprLocalFunctionNode::prep(), KSeExpr::ExprBlockNode::prep(), KSeExpr::ExprIfThenElseNode::prep(), KSeExpr::ExprAssignNode::prep(), KSeExpr::ExprVecNode::prep(), KSeExpr::ExprUnaryOpNode::prep(), KSeExpr::ExprCondNode::prep(), KSeExpr::ExprSubscriptNode::prep(), KSeExpr::ExprCompareEqNode::prep(), KSeExpr::ExprCompareNode::prep(), KSeExpr::ExprBinaryOpNode::prep(), KSeExpr::ExprVarNode::prep(), KSeExpr::ExprNumNode::prep(), KSeExpr::ExprStrNode::prep(), KSeExpr::ExprFuncNode::prep(), setType(), setTypeWithChildLife(), and type().