KSeExpr  4.0.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KSeExpr::ExprNode Class Reference

#include <ExprNode.h>

Inheritance diagram for KSeExpr::ExprNode:
KSeExpr::ExprAssignNode KSeExpr::ExprBinaryOpNode KSeExpr::ExprBlockNode KSeExpr::ExprCompareEqNode KSeExpr::ExprCompareNode KSeExpr::ExprCondNode KSeExpr::ExprFuncNode KSeExpr::ExprIfThenElseNode KSeExpr::ExprLocalFunctionNode KSeExpr::ExprModuleNode KSeExpr::ExprNumNode KSeExpr::ExprPrototypeNode KSeExpr::ExprStrNode KSeExpr::ExprSubscriptNode KSeExpr::ExprUnaryOpNode KSeExpr::ExprVarNode KSeExpr::ExprVecNode

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. More...
 
const Expressionexpr () const
 Access expression. More...
 
std::string toString () const
 Access to original string representation of current expression. More...
 
const ExprTypetype () const
 The type of the node. More...
 
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. 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 ExprNodeparent () const
 Access parent node - root node has no parent. More...
 
int numChildren () const
 Number of children. More...
 
const ExprNodechild (size_t i) const
 Get 0 indexed child. More...
 
ExprNodechild (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...
 
unsigned short int startPos () const
 Access start position in input string. More...
 
unsigned short int endPos () const
 Access end position in input string. More...
 
unsigned short int length () const
 Access length of input string. More...
 
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. More...
 
bool checkIsValue (const ExprType &type, bool &error) const
 Checks if the type is a value (i.e. string or float[d]) More...
 
bool checkIsFP (const ExprType &type, bool &error) const
 Checks if the type is a float[d] for any d. More...
 
bool checkIsFP (int d, const ExprType &type, bool &error) const
 Checks if the type is a float[d] for a specific d. More...
 
bool checkTypesCompatible (const ExprType &first, const ExprType &second, bool &error) const
 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 {nullptr}
 Owning expression (node can't modify) More...
 
ExprNode_parent {nullptr}
 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 {}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ExprNode() [1/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr)

Definition at line 28 of file ExprNode.cpp.

◆ ExprNode() [2/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr,
const ExprType type 
)

Definition at line 34 of file ExprNode.cpp.

◆ ExprNode() [3/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr,
ExprNode a 
)

Definition at line 41 of file ExprNode.cpp.

References _children, and addChild().

◆ ExprNode() [4/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr,
ExprNode a,
const ExprType type 
)

Definition at line 49 of file ExprNode.cpp.

References _children, and addChild().

◆ ExprNode() [5/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr,
ExprNode a,
ExprNode b 
)

Definition at line 58 of file ExprNode.cpp.

References _children, and addChild().

◆ ExprNode() [6/8]

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().

◆ ExprNode() [7/8]

KSeExpr::ExprNode::ExprNode ( const Expression expr,
ExprNode a,
ExprNode b,
ExprNode c 
)

Definition at line 77 of file ExprNode.cpp.

References _children, and addChild().

◆ ExprNode() [8/8]

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().

◆ ~ExprNode()

KSeExpr::ExprNode::~ExprNode ( )
virtual

Definition at line 98 of file ExprNode.cpp.

References _children.

Member Function Documentation

◆ addChild()

void KSeExpr::ExprNode::addChild ( ExprNode child)

Add a child to the child list (for parser use only)

Definition at line 106 of file ExprNode.cpp.

References _children, _parent, and child().

Referenced by addChildren(), ExprNode(), and KSeExpr::GetVar::prep().

◆ addChildren()

void KSeExpr::ExprNode::addChildren ( ExprNode surrogate)

Transfer children from surrogate parent (for parser use only)

Definition at line 112 of file ExprNode.cpp.

References _children, and addChild().

Referenced by KSeExpr::ExprPrototypeNode::addArgs(), and KSeExpr::ExprPrototypeNode::addArgTypes().

◆ addError()

void KSeExpr::ExprNode::addError ( const ErrorCode  error,
const std::vector< std::string > &  ids = {} 
) const
inline

◆ buildInterpreter()

int KSeExpr::ExprNode::buildInterpreter ( Interpreter interpreter) const
virtual

◆ checkCondition()

bool KSeExpr::ExprNode::checkCondition ( bool  check,
const ErrorCode  message,
const std::vector< std::string > &  ids,
bool &  error 
) const
inline

◆ checkIsFP() [1/2]

bool KSeExpr::ExprNode::checkIsFP ( const ExprType type,
bool &  error 
) const
inline

◆ checkIsFP() [2/2]

bool KSeExpr::ExprNode::checkIsFP ( int  d,
const ExprType type,
bool &  error 
) const
inline

Checks if the type is a float[d] for a specific d.

Definition at line 229 of file ExprNode.h.

References checkCondition(), KSeExpr::ExpectedFloatD, KSeExpr::ExprType::isFP(), and type().

◆ checkIsValue()

bool KSeExpr::ExprNode::checkIsValue ( const ExprType type,
bool &  error 
) const
inline

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, KSeExpr::ExprType::isValue(), and type().

Referenced by KSeExpr::ExprCondNode::prep(), and KSeExpr::ExprCompareEqNode::prep().

◆ checkTypesCompatible()

bool KSeExpr::ExprNode::checkTypesCompatible ( const ExprType first,
const ExprType second,
bool &  error 
) const
inline

◆ child() [1/2]

ExprNode* KSeExpr::ExprNode::child ( size_t  i)
inline

Get 0 indexed child.

Definition at line 120 of file ExprNode.h.

References _children.

◆ child() [2/2]

const ExprNode* KSeExpr::ExprNode::child ( size_t  i) const
inline

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(), KSeExpr::ExprFuncStandard::buildInterpreter(), KSeExpr::ExprFuncSimple::buildInterpreter(), buildInterpreter(), KSeExpr::ExprLocalFunctionNode::buildInterpreter(), KSeExpr::ExprIfThenElseNode::buildInterpreter(), KSeExpr::ExprAssignNode::buildInterpreter(), KSeExpr::ExprVecNode::buildInterpreter(), KSeExpr::ExprUnaryOpNode::buildInterpreter(), KSeExpr::ExprSubscriptNode::buildInterpreter(), KSeExpr::ExprCompareNode::buildInterpreter(), KSeExpr::ExprBinaryOpNode::buildInterpreter(), KSeExpr::ExprLocalFunctionNode::buildInterpreterForCall(), KSeExpr::ExprFuncNode::checkArg(), KSeExpr::ExprCurveAssignSpec< T >::ExprCurveAssignSpec(), KSeExpr::ExprFuncNode::getStrArg(), KSeExpr::ExprFuncNode::isStrArg(), KSeExpr::isStrFunc(), 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::ExprFuncStandard::prep(), KSeExpr::GetVar::prep(), KSeExpr::CurveFuncX::prep(), KSeExpr::CCurveFuncX::prep(), KSeExpr::SPrintFuncX::prep(), KSeExpr::ExprLocalFunctionNode::prototype(), setTypeWithChildLife(), and KSeExpr::ExprVecNode::value().

◆ codegen()

virtual LLVM_VALUE KSeExpr::ExprNode::codegen ( LLVM_BUILDER  )
virtual

◆ endPos()

unsigned short int KSeExpr::ExprNode::endPos ( ) const
inline

Access end position in input string.

Definition at line 169 of file ExprNode.h.

References _endPos.

Referenced by KSeExpr::findComment(), length(), and setPosition().

◆ expr()

const Expression* KSeExpr::ExprNode::expr ( ) const
inline

Access expression.

Definition at line 89 of file ExprNode.h.

References _expr.

Referenced by KSeExpr::ExprFuncNode::ExprFuncNode(), KSeExpr::findComment(), KSeExpr::GetVar::prep(), and toString().

◆ isVec()

bool KSeExpr::ExprNode::isVec ( ) const
inline

True if node has a vector result.

Definition at line 83 of file ExprNode.h.

References _isVec.

Referenced by KSeExpr::Expression::isVec().

◆ length()

unsigned short int KSeExpr::ExprNode::length ( ) const
inline

Access length of input string.

Definition at line 174 of file ExprNode.h.

References endPos(), and startPos().

Referenced by toString().

◆ numChildren()

int KSeExpr::ExprNode::numChildren ( ) const
inline

◆ parent()

const ExprNode* KSeExpr::ExprNode::parent ( ) const
inline

Access parent node - root node has no parent.

Definition at line 103 of file ExprNode.h.

References _parent.

Referenced by KSeExpr::TypePrintExaminer::examine().

◆ prep()

ExprType KSeExpr::ExprNode::prep ( bool  dontNeedScalar,
ExprVarEnvBuilder envBuilder 
)
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::ExprFuncNode, KSeExpr::ExprStrNode, KSeExpr::ExprNumNode, KSeExpr::ExprVarNode, KSeExpr::ExprBinaryOpNode, KSeExpr::ExprCompareNode, KSeExpr::ExprCompareEqNode, KSeExpr::ExprSubscriptNode, KSeExpr::ExprCondNode, KSeExpr::ExprUnaryOpNode, KSeExpr::ExprVecNode, KSeExpr::ExprAssignNode, KSeExpr::ExprIfThenElseNode, KSeExpr::ExprBlockNode, KSeExpr::ExprLocalFunctionNode, KSeExpr::ExprPrototypeNode, and KSeExpr::ExprModuleNode.

Definition at line 121 of file ExprNode.cpp.

References _maxChildDim, _type, child(), KSeExpr::ExprType::dim(), KSeExpr::ExprType::isFP(), KSeExpr::ExprType::isValid(), KSeExpr::None, numChildren(), prep(), setType(), setTypeWithChildLife(), and type().

Referenced by KSeExpr::ExprFuncNode::checkArg(), KSeExpr::Expression::prep(), 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::ExprFuncNode::prep(), KSeExpr::ExprFuncStandard::prep(), and KSeExpr::GetVar::prep().

◆ removeLastChild()

void KSeExpr::ExprNode::removeLastChild ( )
inline

Remove last child and delete the entry.

Definition at line 133 of file ExprNode.h.

References _children.

Referenced by KSeExpr::GetVar::prep().

◆ setPosition()

void KSeExpr::ExprNode::setPosition ( const short int  startPos,
const short int  endPos 
)
inline

Remember the line and column position in the input string.

Definition at line 158 of file ExprNode.h.

References _endPos, _startPos, endPos(), and startPos().

◆ setType()

void KSeExpr::ExprNode::setType ( const ExprType t)
inlineprotected

◆ setTypeWithChildLife()

void KSeExpr::ExprNode::setTypeWithChildLife ( const ExprType t)
inlineprotected

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().

◆ startPos()

unsigned short int KSeExpr::ExprNode::startPos ( ) const
inline

Access start position in input string.

Definition at line 164 of file ExprNode.h.

References _startPos.

Referenced by length(), setPosition(), and toString().

◆ swapChildren()

void KSeExpr::ExprNode::swapChildren ( size_t  i,
size_t  j 
)
inline

Swap children, do not use unless you know what you are doing.

Definition at line 126 of file ExprNode.h.

References _children.

Referenced by KSeExpr::GetVar::prep().

◆ toString()

std::string KSeExpr::ExprNode::toString ( ) const
inline

Access to original string representation of current expression.

Definition at line 95 of file ExprNode.h.

References expr(), KSeExpr::Expression::getExpr(), length(), and startPos().

Referenced by KSeExpr::TypePrintExaminer::examine().

◆ type()

const ExprType& KSeExpr::ExprNode::type ( ) const
inline

Member Data Documentation

◆ _children

std::vector<ExprNode *> KSeExpr::ExprNode::_children
protected

List of children.

Definition at line 247 of file ExprNode.h.

Referenced by addChild(), addChildren(), child(), ExprNode(), numChildren(), removeLastChild(), swapChildren(), and ~ExprNode().

◆ _endPos

unsigned short int KSeExpr::ExprNode::_endPos {}
protected

Definition at line 257 of file ExprNode.h.

Referenced by endPos(), and setPosition().

◆ _expr

const Expression* KSeExpr::ExprNode::_expr {nullptr}
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().

◆ _isVec

bool KSeExpr::ExprNode::_isVec
protected

True if node has a vector result.

Definition at line 250 of file ExprNode.h.

Referenced by isVec().

◆ _maxChildDim

int KSeExpr::ExprNode::_maxChildDim {}
protected

Definition at line 254 of file ExprNode.h.

Referenced by prep().

◆ _parent

ExprNode* KSeExpr::ExprNode::_parent {nullptr}
protected

Parent node (null if this the the root)

Definition at line 244 of file ExprNode.h.

Referenced by addChild(), and parent().

◆ _startPos

unsigned short int KSeExpr::ExprNode::_startPos {}
protected

Position line and collumn.

Definition at line 257 of file ExprNode.h.

Referenced by setPosition(), and startPos().

◆ _type

ExprType KSeExpr::ExprNode::_type
protected

The documentation for this class was generated from the following files: