Joos1W Compiler Framework
All Classes Functions Typedefs Pages
parsetree::Node Struct Reference

The basic type-tagged node in the parse tree. More...

#include <ParseTree.h>

Inheritance diagram for parsetree::Node:

Public Member Functions

size_t num_children () const
 Gets the number of children.
 
Nodechild (size_t i) const
 Gets the child at index i.
 
Type get_node_type () const
 Gets the type of the node.
 
std::string type_string () const
 Operator to turn Type into a string.
 
bool is_poisoned () const
 Check if the tree has been poisoned.
 
SourceRange location () const
 Get the location of the node.
 
Node const * parent () const
 Get the parent of the node.
 
Nodeparent ()
 
void mark ()
 
bool is_marked () const
 
virtual std::ostream & print (std::ostream &os) const
 Virtual function to print the node.
 
std::ostream & printDot (std::ostream &os) const
 Print the node as a dot file.
 

Static Public Member Functions

static std::string type_string (Type type)
 Operator to turn Type into a string.
 

Protected Member Functions

 Node (SourceRange loc, Type type)
 The enum for each node type. More...
 
template<typename... Args>
 Node (SourceRange loc, BumpAllocator &alloc, Type type, Args &&... args)
 Protected constructor for non-leaf nodes. More...
 
virtual void printDotNode (DotPrinter &dp) const
 Custom function to print the DOT node.
 

Friends

class ::Joos1WLexer
 
class ::Joos1WParser
 

Detailed Description

The basic type-tagged node in the parse tree.

Definition at line 29 of file ParseTree.h.

Constructor & Destructor Documentation

◆ Node() [1/2]

parsetree::Node::Node ( SourceRange  loc,
Type  type 
)
inlineprotected

The enum for each node type.

Protected constructor for leaf nodes

Parameters
typeThe type of the leaf node

Definition at line 100 of file ParseTree.h.

101  : loc{loc}, type{type}, args{nullptr}, num_args{0}, parent_{nullptr} {}

Referenced by Joos1WLexer::make_leaf(), and Joos1WLexer::make_poison().

◆ Node() [2/2]

template<typename... Args>
parsetree::Node::Node ( SourceRange  loc,
BumpAllocator &  alloc,
Type  type,
Args &&...  args 
)
inlineprotected

Protected constructor for non-leaf nodes.

Template Parameters
...ArgsThe child node types (should be Node*)
Parameters
typeThe type of the node
...argsThe child nodes

Definition at line 108 of file ParseTree.h.

109  : loc{loc},
110  type{type},
111  args{static_cast<Node**>(alloc.allocate_bytes(
112  sizeof...(Args) * sizeof(Node*), alignof(Node*)))},
113  num_args{sizeof...(Args)} {
114  static_assert(sizeof...(Args) > 0, "Must have at least one child");
115  static_assert(std::conjunction_v<std::is_convertible<Args, Node*>...>,
116  "All arguments must be convertible to Node*");
117  std::array<Node*, sizeof...(Args)> tmp{std::forward<Args>(args)...};
118  for(size_t i = 0; i < sizeof...(Args); i++) {
119  this->args[i] = tmp[i];
120  if(this->args[i] != nullptr) this->args[i]->parent_ = this;
121  }
122  }
The basic type-tagged node in the parse tree.
Definition: ParseTree.h:29

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