Pegmatite
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
pegmatite::ASTNode Class Referenceabstract

Base class for AST nodes. More...

#include <ast.hh>

Inheritance diagram for pegmatite::ASTNode:
pegmatite::ASTContainer

Public Member Functions

 ASTNode ()
 Constructs the AST node, with a null parent.
 
 ASTNode (const ASTNode &)=delete
 Copying AST nodes is not supported.
 
virtual ~ASTNode ()
 Destructor does nothing, virtual for subclasses to use. More...
 
ASTNodeparent () const
 Returns the parent of this AST node, or nullptr if there isn't one (either if this is the root, or if it is still in the stack waiting to be added to the tree).
 
virtual void construct (const InputRange &r, ASTStack &st)=0
 Interface for constructing the AST node. More...
 
virtual bool isa (char *x)
 Root implementation of the RTTI-replacement for builds not wishing to use RTTI. More...
 
template<class T >
bool isa ()
 Returns true if this object is an instance of T. More...
 
template<class T >
T * get_as ()
 Returns a pointer to this object as a pointer to a child class, or nullptr if the cast would be unsafe. More...
 

Protected Member Functions

virtual char * kind ()
 Returns the kind of object class. More...
 

Static Protected Member Functions

static char * classKind ()
 Returns the unique identifier for this class.
 

Friends

template<class T , bool Optional>
class ASTPtr
 
template<class T >
class ASTList
 
template<class T >
class BindAST
 

Detailed Description

Base class for AST nodes.

Constructor & Destructor Documentation

virtual pegmatite::ASTNode::~ASTNode ( )
virtual

Destructor does nothing, virtual for subclasses to use.

Defined out-of-line to avoid emitting vtables in every translation unit that includes this header.

Member Function Documentation

virtual void pegmatite::ASTNode::construct ( const InputRange r,
ASTStack &  st 
)
pure virtual

Interface for constructing the AST node.

The input range r is the range within the source.

Implemented in pegmatite::ASTContainer.

template<class T >
T* pegmatite::ASTNode::get_as ( )
inline

Returns a pointer to this object as a pointer to a child class, or nullptr if the cast would be unsafe.

Note that AST nodes are intended to be always used as unique pointers and so the returned object is only valid as long as the unique pointer is valid.

virtual bool pegmatite::ASTNode::isa ( char *  x)
inlinevirtual

Root implementation of the RTTI-replacement for builds not wishing to use RTTI.

This returns true if x is the value returned from classKind(), or false otherwise.

template<class T >
bool pegmatite::ASTNode::isa ( )
inline

Returns true if this object is an instance of T.

Note that this only works with single-inheritance hierarchies. If you wish to use multiple inheritance in your AST classes, then you must define USE_RTTI and use the C++ RTTI mechanism.

virtual char* pegmatite::ASTNode::kind ( )
inlineprotectedvirtual

Returns the kind of object class.

This is a unique pointer that can be tested against pointers returned by classKind() to determine whether they can be safely compared.


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