taco-db  0.1.0
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
taco::TreeNode Class Referenceabstract

TreeNode is the base class of all tree structures in TDB (e.g., parsing tree, logical plan, physical plan, query execution state). More...

#include <utils/tree/TreeNode.h>

Inheritance diagram for taco::TreeNode:
taco::ExprNode taco::PlanExecState taco::PlanNode taco::AndOperator taco::BinaryOperator taco::Cast taco::FuncCallOperator taco::Literal taco::OrOperator taco::UnaryOperator taco::Variable taco::AggregationState taco::CartesianProductState taco::IndexScanState taco::LimitState taco::ProjectionState taco::SelectionState taco::SortState taco::TableDeleteState taco::TableInsertState taco::TableScanState taco::TempTableState taco::Aggregation taco::CartesianProduct taco::IndexScan taco::Limit taco::Projection taco::Selection taco::Sort taco::TableDelete taco::TableInsert taco::TableScan taco::TempTable

Public Member Functions

template<class ... UniquePtrs>
 TreeNode (NodeTag tag, UniquePtrs &&...input)
 
virtual ~TreeNode ()
 
 TreeNode (TreeNode &&)=default
 
TreeNodeoperator= (TreeNode &&)=default
 
 TreeNode (const TreeNode &)=delete
 
TreeNodeoperator= (const TreeNode &)=delete
 
constexpr NodeTag get_tag () const
 
TreeNodeget_input (size_t i) const
 
template<class Node >
Node * get_input_as (size_t i) const
 
std::string to_string () const
 
void node_to_string (std::string &buf, int indent) const
 Prints the node contents to a string buffer. More...
 
const char * node_name () const
 
virtual void node_properties_to_string (std::string &buf, int indent) const =0
 

Static Public Member Functions

static void append_indent (std::string &buf, int indent)
 

Private Attributes

NodeTag m_tag
 
std::vector< std::unique_ptr< TreeNode > > m_input
 

Static Private Attributes

static constexpr const int TO_STRING_INDENT_SIZE = 4
 

Detailed Description

TreeNode is the base class of all tree structures in TDB (e.g., parsing tree, logical plan, physical plan, query execution state).

Each TreeNode can have zero or more inputs, and it owns the objects by storing a unique_ptr to it. TreeNode constructors constructors and destructors should only allocate/deallocate memory and perform initialization that may not generate an error (e.g., initializing fields with trivial constructors). Any initialization that may generate an error must be done in a separate function call, that communicates the error to the caller through the return value. Similarly, clean-up of a node that may produce some error must be done in a separate function other than the destructor with a return status.

A TreeNode object is owned by another TreeNode or some function scope that has a unique_ptr to it. As a result, a TreeNode object may only be explicitly moved as a unique_ptr or referenced through a raw pointer. It may not be shallow copied and the copy constructor and the copy assignment operator is deleted. The owner of a node is responsible to keep it alive while there are references to the object. That being said, the most common pattern is to never delete objects unless the entire tree goes is being deleted. If you need to update an input without changing the inputs of the input, most likely you'll have to replace the entire subtree anyway (since we do not allow shallow copies). The original node will be deleted when the entire tree is deleted.

Each TreeNode object is associated with a tag (NodeTag). It identifies the type of the TreeNode object. We use the tag rather than RTTI to cast or identify TreeNode – that will probably be more flexible and faster at the cost of an additional 8-byte overhead (2 bytes + padding) per node.

Constructor & Destructor Documentation

◆ TreeNode() [1/3]

template<class ... UniquePtrs>
taco::TreeNode::TreeNode ( NodeTag  tag,
UniquePtrs &&...  input 
)
inline

◆ ~TreeNode()

virtual taco::TreeNode::~TreeNode ( )
inlinevirtual

◆ TreeNode() [2/3]

taco::TreeNode::TreeNode ( TreeNode &&  )
default

◆ TreeNode() [3/3]

taco::TreeNode::TreeNode ( const TreeNode )
delete

Member Function Documentation

◆ append_indent()

void taco::TreeNode::append_indent ( std::string &  buf,
int  indent 
)
static

◆ get_input()

TreeNode* taco::TreeNode::get_input ( size_t  i) const
inline

◆ get_input_as()

template<class Node >
Node* taco::TreeNode::get_input_as ( size_t  i) const
inline

◆ get_tag()

constexpr NodeTag taco::TreeNode::get_tag ( ) const
inlineconstexpr

◆ node_name()

const char* taco::TreeNode::node_name ( ) const
inline

◆ node_properties_to_string()

virtual void taco::TreeNode::node_properties_to_string ( std::string &  buf,
int  indent 
) const
pure virtual

◆ node_to_string()

void taco::TreeNode::node_to_string ( std::string &  buf,
int  indent 
) const

Prints the node contents to a string buffer.

No indentation is added on the first line, and all subsequent lines have an indentation of at least indent * INDENT_SIZE spaces.

◆ operator=() [1/2]

TreeNode& taco::TreeNode::operator= ( const TreeNode )
delete

◆ operator=() [2/2]

TreeNode& taco::TreeNode::operator= ( TreeNode &&  )
default

◆ to_string()

std::string taco::TreeNode::to_string ( ) const
inline

Member Data Documentation

◆ m_input

std::vector<std::unique_ptr<TreeNode> > taco::TreeNode::m_input
private

◆ m_tag

NodeTag taco::TreeNode::m_tag
private

◆ TO_STRING_INDENT_SIZE

constexpr const int taco::TreeNode::TO_STRING_INDENT_SIZE = 4
staticconstexprprivate

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