SeExpr
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SeExpr2::ExprNode Class Reference

#include <ExprNode.h>

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

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

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 72 of file ExprNode.h.

Constructor & Destructor Documentation

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

SeExpr2::ExprNode::~ExprNode ( )
virtual

Definition at line 82 of file ExprNode.cpp.

References _children.

Member Function Documentation

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

void SeExpr2::ExprNode::addError ( const std::string &  error) const
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().

int SeExpr2::ExprNode::buildInterpreter ( Interpreter interpreter) const
virtual
bool SeExpr2::ExprNode::checkCondition ( bool  check,
const std::string &  message,
bool &  error 
)
inline
bool SeExpr2::ExprNode::checkIsFP ( const ExprType type,
bool &  error 
)
inline
bool SeExpr2::ExprNode::checkIsFP ( int  d,
const ExprType type,
bool &  error 
)
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().

bool SeExpr2::ExprNode::checkIsValue ( const ExprType type,
bool &  error 
)
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().

bool SeExpr2::ExprNode::checkTypesCompatible ( const ExprType first,
const ExprType second,
bool &  error 
)
inline
const ExprNode* SeExpr2::ExprNode::child ( size_t  i) const
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().

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

Get 0 indexed child.

Definition at line 120 of file ExprNode.h.

References _children.

virtual LLVM_VALUE SeExpr2::ExprNode::codegen ( LLVM_BUILDER  )
virtual
short int SeExpr2::ExprNode::endPos ( ) const
inline

Access end position in input string.

Definition at line 159 of file ExprNode.h.

References _endPos.

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

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

Access expression.

Definition at line 102 of file ExprNode.h.

References _expr.

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

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

True if node has a vector result.

Definition at line 99 of file ExprNode.h.

References _isVec.

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

short int SeExpr2::ExprNode::length ( ) const
inline

Access length of input string.

Definition at line 161 of file ExprNode.h.

References endPos(), and startPos().

Referenced by toString().

int SeExpr2::ExprNode::numChildren ( ) const
inline
const ExprNode* SeExpr2::ExprNode::parent ( ) const
inline

Access parent node - root node has no parent.

Definition at line 112 of file ExprNode.h.

References _parent.

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

ExprType SeExpr2::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 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().

void SeExpr2::ExprNode::removeLastChild ( )
inline

Remove last child and delete the entry.

Definition at line 129 of file ExprNode.h.

References _children.

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

void SeExpr2::ExprNode::setPosition ( const short int  startPos,
const short int  endPos 
)
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().

void SeExpr2::ExprNode::setType ( const ExprType t)
inlineprotected
void SeExpr2::ExprNode::setTypeWithChildLife ( const ExprType t)
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().

short int SeExpr2::ExprNode::startPos ( ) const
inline

Access start position in input string.

Definition at line 157 of file ExprNode.h.

References _startPos.

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

void SeExpr2::ExprNode::swapChildren ( size_t  i,
size_t  j 
)
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().

std::string SeExpr2::ExprNode::toString ( ) const
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().

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

Member Data Documentation

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

List of children.

Definition at line 231 of file ExprNode.h.

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

unsigned short int SeExpr2::ExprNode::_endPos
protected

Definition at line 241 of file ExprNode.h.

Referenced by addError(), endPos(), and setPosition().

const Expression* SeExpr2::ExprNode::_expr
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().

bool SeExpr2::ExprNode::_isVec
protected

True if node has a vector result.

Definition at line 234 of file ExprNode.h.

Referenced by isVec().

int SeExpr2::ExprNode::_maxChildDim
protected

Definition at line 238 of file ExprNode.h.

Referenced by prep().

ExprNode* SeExpr2::ExprNode::_parent
protected

Parent node (null if this the the root)

Definition at line 228 of file ExprNode.h.

Referenced by addChild(), and parent().

unsigned short int SeExpr2::ExprNode::_startPos
protected

Position line and collumn.

Definition at line 241 of file ExprNode.h.

Referenced by addError(), setPosition(), and startPos().

ExprType SeExpr2::ExprNode::_type
protected

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